-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
152 lines (131 loc) · 4.06 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
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
{
description = "A personal collection of unusual things";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
nix-github-actions.url = "github:nix-community/nix-github-actions";
nix-github-actions.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, nix-github-actions }:
let
inherit (nixpkgs.lib)
getAttrs
mapAttrs'
mapAttrsToList
pipe
recursiveUpdate
;
merge = builtins.foldl' recursiveUpdate { };
##########################################
mkPackages = system:
let
dir = ./packages;
pkgs = import nixpkgs {
inherit system;
overlays = [ (_: _: packages) ];
};
packages = pipe dir [
builtins.readDir
(mapAttrs' (file: _: {
name = builtins.replaceStrings [ ".nix" ] [ "" ] file;
value = import "${dir}/${file}" pkgs;
}))
];
in
{ packages.${system} = packages; };
allPackages = merge (map mkPackages
[ "x86_64-linux" "aarch64-linux" ]);
##########################################
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
nvidia =
let
nvidia = pkgs.linuxPackages_zen.nvidiaPackages;
mkNvidia = nvidia: [
nvidia
nvidia.persistenced
nvidia.settings
];
in
pipe [
(mkNvidia nvidia.production)
(mkNvidia nvidia.stable)
[ pkgs.nvtopPackages.nvidia ]
] [
builtins.concatLists
(pkgs.linkFarmFromDrvs "nvidia")
];
rawMatrix = pipe self.githubActions.matrix [
builtins.toJSON
(pkgs.writeText "rawMatrix")
];
in
allPackages // {
githubActions = nix-github-actions.lib.mkGithubMatrix {
checks = merge [
(getAttrs [ system ] self.packages)
{ ${system} = { inherit nvidia; }; }
];
};
nixosModules."9mount" = import ./packages/9mount/module.nix {
packages = self.packages;
};
templates = let dir = ./templates; in pipe dir [
builtins.readDir
builtins.attrNames
(map (name: {
inherit name;
value = {
description = "${name} template";
path = "${dir}/${name}";
};
}))
builtins.listToAttrs
];
##########################################
readme = pipe self.packages.${pkgs.system} [
(mapAttrsToList (name: p:
"|`${name}`|`${p.version or "n/a"}`|${p.meta.description or ""}|${p.meta.homepage or ""}|"))
(x: pipe x [
(builtins.concatStringsSep "\n")
(s: pipe ./README.md.in [
builtins.readFile
(builtins.replaceStrings
[ "@NUM@" ]
[ (toString (builtins.length x)) ])
(x: x + s + "\n")
])
(s: pkgs.writeShellScriptBin "readme" ''
cat <<\EOF > README.md
${s}
EOF
'')
])
];
matrix = pkgs.writeShellApplication {
name = "matrix";
runtimeInputs = with pkgs; [ curl jq parallel ];
text = ''
check() {
read -r attr os <<< "$1"
nar="$(nix eval --raw ".#$attr" | cut -b 12-43)"
if curl -fs "https://attic.eleonora.gay/default/$nar.narinfo" > /dev/null; then
state="[1;32mCACHE[m"
else
state="[1;31mBUILD[m"
jq -cn '{attr: $ARGS.positional[0], os: $ARGS.positional[1]}' \
--args "$attr" "$os"
fi
echo "[$state] $nar $attr" >&3
}
export -f check
< ${rawMatrix} \
jq -r '.include[] | "\(.attr) \(.os[])"' \
| parallel check 3>&2 2>/dev/null \
| jq -cs 'if . == [] then empty else {"include": .} end'
'';
};
};
}