-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
108 lines (89 loc) · 3 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
{
description = "Organize groups of scripts into documented CLIs with subcommands";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
devenv = {
url = "github:cachix/devenv";
inputs.nixpkgs.follows = "nixpkgs";
};
};
nixConfig = {
extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
extra-substituters = "https://devenv.cachix.org";
};
outputs = { self, nixpkgs, flake-utils, devenv, ... } @ inputs:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system}; in
rec {
packages = {
default = packages.sub;
sub = pkgs.callPackage ./default.nix { inherit pkgs; };
};
legacyPackages = {
default = packages.sub;
sub = packages.sub;
};
lib = {
mkSubDerivation = args@{ pname, cmd ? pname, buildInputs ? [ ], ... }:
pkgs.stdenv.mkDerivation (args // {
buildInputs = [ packages.sub pkgs.rsync ];
buildPhase = "true";
installPhase = ''
mkdir -p $out/bin
echo foo
cat <<EOF >$out/bin/${cmd}
#!/usr/bin/env bash
set -e
${packages.sub}/bin/sub --name ${cmd} --absolute "$out/opt/${pname}" -- "\$@"
EOF
chmod a+x $out/bin/${cmd}
mkdir -p $out/opt/${pname}/lib
if [ -e lib ]; then
rsync -rp lib/ $out/opt/${pname}/lib/
fi
mkdir -p $out/opt/${pname}/libexec
if [ -e libexec ]; then
rsync -rp libexec/ $out/opt/${pname}/libexec/
fi
cat <<EOF >$out/opt/${pname}/completions.zsh
if [[ ! -o interactive ]]; then
return
fi
compctl -K _${cmd} ${cmd}
_${cmd}() {
local words completions
read -cA words
if [ "\''${#words}" -eq 2 ]; then
completions="\$(${cmd} --completions)"
else
completions="\$(${cmd} --completions "\''${words[@]:1:-1}")"
fi
reply=("\''${(ps:\n:)completions}")
}
EOF
chmod a+x $out/opt/${pname}/completions.zsh
'';
});
};
apps = {
default = apps.sub;
sub = flake-utils.lib.mkApp { drv = packages.sub; };
};
devShells = {
default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
{
packages = with pkgs; [
asciinema
bats
doitlive
];
languages.rust.enable = true;
}
];
};
};
});
}