forked from BrianHicks/nix-script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
168 lines (148 loc) · 5.57 KB
/
flake.nix
File metadata and controls
168 lines (148 loc) · 5.57 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
{
description =
"write scripts in compiled languages that run in the nix ecosystem, with no separate build step";
inputs = {
utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/release-21.05";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = inputs@{ self, nixpkgs, utils, flake-compat }:
(utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlay ];
config = { allowUnsupportedSystem = true; };
};
nix-script-shell = with pkgs; [
nix-script
nix-script-haskell
nix-script-bash
(haskellPackages.ghcWithPackages (p: with p; [ relude ]))
];
in rec {
packages = {
inherit (pkgs) nix-script nix-script-bash nix-script-haskell;
};
defaultPackage = pkgs.nix-script;
devShell = with pkgs;
mkShell {
buildInputs = [
cabal-install
haskellPackages.ghcid
haskellPackages.hlint
haskellPackages.ormolu
nix-script-shell
nixfmt
];
};
apps = {
tests = utils.lib.mkApp {
drv = with import nixpkgs { inherit system; };
pkgs.writeShellScriptBin "nix-script-example-checks" ''
set -xeuo pipefail
export NIX_SCRIPT_CACHE_PATH=".nix-script-cache"
export PATH=${
pkgs.lib.strings.makeBinPath
([ pkgs.nixUnstable findutils coreutils ] ++ nix-script-shell)
}
(
cd nix-script
samples/test-has-script-file.hs
samples/test-receives-arguments.hs a b c
samples/test-receives-flags.hs --help
samples/test-has-runtime-input.hs
samples/test-program-name.hs
# regression test: we should not error out if the underlying
# builds get GC'd
find "$NIX_SCRIPT_CACHE_PATH" -type l \
| xargs --no-run-if-empty -n 1 readlink \
| xargs --no-run-if-empty nix-store --delete
samples/test-program-name.hs
)
(
cd nix-script-bash
samples/hello-world.sh
samples/with-dependencies.sh
)
(
cd nix-script-haskell
samples/hello-world.hs
samples/with-dependencies.hs
samples/no-extension
samples/test-receives-flags.hs --help
)
'';
};
# nix run .#lint for checking that source files are lint-free
lint = utils.lib.mkApp {
drv = with import nixpkgs { inherit system; };
pkgs.writeShellScriptBin "nix-script-lint" ''
set -xeuo pipefail
export PATH=${
pkgs.lib.strings.makeBinPath [
nixfmt
haskellPackages.hlint
findutils
]
}
nixfmt --check $(find . -name '*.nix')
( cd nix-script; hlint . )
( cd nix-script-haskell; hlint . )
'';
};
# nix run .#cabal2nix for updating cabal2nix files
cabal2nix = utils.lib.mkApp {
drv = with import nixpkgs { inherit system; };
pkgs.writeShellScriptBin "nix-script-cabal2nix" ''
set -xeuo pipefail
export PATH=${pkgs.lib.strings.makeBinPath [ cabal2nix nixfmt ]}
(
cd nix-script
cabal2nix . > default.nix
nixfmt default.nix
)
(
cd nix-script-haskell
cabal2nix . > default.nix
nixfmt default.nix
)
'';
};
};
})) // {
overlay = final: prev: {
haskellPackages = prev.haskellPackages.override (old: {
overrides =
final.lib.composeExtensions (old.overrides or (_: _: { }))
(hself: hsuper: {
nix-script = with final.haskell.lib;
generateOptparseApplicativeCompletion "nix-script"
(overrideCabal (prev.haskellPackages.callPackage ./nix-script
{ }
#prev.haskellPackages.callCabal2nix "nix-script" ./nix-script { }
) (drv: {
buildTools = drv.buildTools or [ ] ++ [ final.makeWrapper ];
postInstall = with final;
drv.postInstall or "" + ''
wrapProgram $out/bin/nix-script \
--set NIX_PATH "nixpkgs=${final.path}" \
--prefix PATH ":" "${lib.makeBinPath [ nixUnstable ]}"
'';
}));
nix-script-haskell =
prev.haskellPackages.callPackage ./nix-script-haskell { };
});
});
nix-script = with final;
haskell.lib.justStaticExecutables haskellPackages.nix-script;
nix-script-haskell = with final;
haskell.lib.justStaticExecutables
haskellPackages.nix-script-haskell;
nix-script-bash = prev.callPackage ./nix-script-bash { };
};
};
}