This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
flake.nix
121 lines (105 loc) · 3.49 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
naersk.url = "github:nix-community/naersk";
naersk.inputs.nixpkgs.follows = "nixpkgs";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = inputs:
let
rustTarget = { name, version, pkgs, naersk-lib, postInstall ? "" }:
naersk-lib.buildPackage {
inherit name;
inherit version;
inherit postInstall;
root = ./.;
buildInputs = [ pkgs.clippy pkgs.makeWrapper ];
target = [ name ];
doCheck = true;
checkPhase = ''
cargo clippy -- --deny warnings
# make sure we've listed the right version here (we can't grab
# it from the manifest because we use a virtual manifest for the
# various targets.) If this test fails, fix by making the `version`
# attribute the same as the one in `nix-script/Cargo.toml`
grep -q -e 'version = "${version}"' ${name}/Cargo.toml
'';
copyBinsFilter = ''
select(.reason == "compiler-artifact" and .executable != null and .profile.test == false and .target.name == "${name}")'';
};
mkNixScript = pkgs: naersk-lib:
rustTarget {
name = "nix-script";
version = "2.0.0";
inherit pkgs;
inherit naersk-lib;
};
mkNixScriptBash = pkgs:
pkgs.writeShellScriptBin "nix-script-bash" ''
exec ${pkgs.nix-script}/bin/nix-script \
--build-command 'cp $SRC $OUT' \
--interpreter bash \
"$@"
'';
mkNixScriptHaskell = pkgs: naersk-lib:
rustTarget rec {
name = "nix-script-haskell";
version = "2.0.0";
inherit pkgs;
inherit naersk-lib;
postInstall = ''
# avoid trying to package the dependencies step
if test -f $out/bin/${name}; then
wrapProgram $out/bin/${name} \
--prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.nix-script ]}
fi
'';
};
mkNixScriptAll = pkgs:
pkgs.symlinkJoin {
name = "nix-script-all";
paths =
[ pkgs.nix-script pkgs.nix-script-haskell pkgs.nix-script-bash ];
};
in {
overlay = final: prev:
let naersk-lib = inputs.naersk.lib."${final.system}";
in {
nix-script = mkNixScript prev naersk-lib;
nix-script-bash = mkNixScriptBash final;
nix-script-haskell = mkNixScriptHaskell final naersk-lib;
nix-script-all = mkNixScriptAll final;
};
} // inputs.flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ inputs.self.overlay ];
};
in {
packages = {
nix-script = pkgs.nix-script;
nix-script-bash = pkgs.nix-script-bash;
nix-script-haskell = pkgs.nix-script-haskell;
nix-script-all = pkgs.nix-script-all;
};
defaultPackage = pkgs.nix-script-all;
devShell = pkgs.mkShell {
NIX_PKGS = inputs.nixpkgs;
packages = [
# rust
pkgs.rustc
pkgs.cargo
pkgs.cargo-edit
pkgs.clippy
pkgs.rustPackages.rustfmt
# system
pkgs.libiconv
];
};
});
}