Skip to content

Commit c9899c2

Browse files
committed
refactor(scripts): move to scripts.nix
1 parent a3c97ff commit c9899c2

File tree

2 files changed

+56
-48
lines changed

2 files changed

+56
-48
lines changed

flake.nix

+13-48
Original file line numberDiff line numberDiff line change
@@ -8,62 +8,27 @@
88

99
outputs = { self, nixpkgs, utils }: {
1010

11+
overlay = final: prev:
12+
let scripts = prev.callPackage ./scripts.nix { }; in
13+
{
14+
inherit (scripts) format update test-develop dvt;
15+
};
16+
1117
templates = import ./templates.nix;
1218

1319
} // utils.lib.eachDefaultSystem (system:
1420
let
15-
pkgs = import nixpkgs { inherit system; };
16-
17-
inherit (pkgs) mkShell writeScriptBin;
18-
19-
run = pkg: "${pkgs.${pkg}}/bin/${pkg}";
20-
21-
dvt = writeScriptBin "dvt"
22-
''
23-
if [ -z $1 ]; then
24-
echo "no template specified"
25-
exit 1
26-
fi
27-
TEMPLATE=$1
28-
${run "nix"} \
29-
--experimental-features 'nix-command flakes' \
30-
flake init \
31-
--template \
32-
"github:efishery/dvt#''${TEMPLATE}"
33-
'';
34-
35-
format = writeScriptBin "format"
36-
''
37-
${run "nixpkgs-fmt"} **/*.nix
38-
'';
39-
40-
update = writeScriptBin "update"
41-
''
42-
for dir in `ls -d */`; do
43-
(
44-
cd $dir
45-
${run "nix"} flake update # Update flake.lock
46-
${run "nix"} develop $dir # Make sure this work after update
47-
)
48-
done
49-
'';
50-
51-
test-develop = writeScriptBin "test-develop"
52-
''
53-
for dir in `ls -d */`; do
54-
(
55-
${run "nix"} develop $dir # Make sure this work after update
56-
sleep 0.2
57-
)
58-
done
59-
'';
21+
overlays = [ (self.overlay) ];
22+
pkgs = import nixpkgs { inherit system overlays; };
6023
in
6124
{
62-
devShells.default = mkShell { buildInputs = [ format update ]; };
25+
devShells.default = pkgs.mkShell { buildInputs = with pkgs; [ format update ]; };
6326

6427
packages = {
65-
default = dvt;
66-
inherit dvt test-develop;
28+
dvt-init = pkgs.dvt;
29+
dvt-format = pkgs.format;
30+
dvt-update = pkgs.update;
31+
inherit (pkgs) test-develop;
6732
};
6833
});
6934
}

scripts.nix

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{ writeScriptBin, nix, nixpkgs-fmt }:
2+
{
3+
update = writeScriptBin "update"
4+
''
5+
for dir in `ls -d */`; do
6+
(
7+
cd $dir
8+
${nix}/bin/nix flake update # Update flake.lock
9+
${nix}/bin/nix develop $dir # Make sure this work after update
10+
)
11+
done
12+
'';
13+
14+
test-develop = writeScriptBin "test-develop"
15+
''
16+
for dir in `ls -d */`; do
17+
(
18+
${nix}/bin/nix develop $dir # Make sure this work after update
19+
sleep 0.2
20+
)
21+
done
22+
'';
23+
24+
format = writeScriptBin "format"
25+
''
26+
${nixpkgs-fmt}/bin/nixpkgs-fmt **/*.nix
27+
'';
28+
29+
dvt = writeScriptBin "dvt"
30+
''
31+
if [ -z $1 ]; then
32+
echo "no template specified"
33+
exit 1
34+
fi
35+
TEMPLATE=$1
36+
${nix}/bin/nix \
37+
--experimental-features 'nix-command flakes' \
38+
flake init \
39+
--template \
40+
"github:efishery/dvt#''${TEMPLATE}"
41+
'';
42+
}
43+

0 commit comments

Comments
 (0)