-
Notifications
You must be signed in to change notification settings - Fork 6
/
flake.nix
128 lines (119 loc) · 4.25 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
{
description = "NixOS Facter Modules";
outputs =
publicInputs:
let
loadPrivateFlake =
path:
let
flakeHash = builtins.readFile "${toString path}.narHash";
flakePath = "path:${toString path}?narHash=${flakeHash}";
in
builtins.getFlake (builtins.unsafeDiscardStringContext flakePath);
privateFlake = loadPrivateFlake ./dev/private;
privateInputs = privateFlake.inputs;
systems = [
"aarch64-linux"
"riscv64-linux"
"x86_64-linux"
];
eachSystem =
f:
builtins.listToAttrs (
builtins.map (system: {
name = system;
value = f {
pkgs = privateInputs.nixpkgs.legacyPackages.${system};
inherit system;
};
}) systems
);
in
{
lib = import ./lib { inherit (privateInputs.nixpkgs) lib; };
nixosConfigurations = {
basic =
(import ./hosts/basic {
inputs = privateInputs;
flake = publicInputs.self;
}).value;
};
nixosModules.facter = ./modules/nixos/facter.nix;
}
//
# DevOutputs
{
devShells = eachSystem (
{ pkgs, ... }:
{
default = pkgs.callPackage ./devshell.nix { inputs = publicInputs // privateInputs; };
docs = pkgs.callPackage ./docs.nix { inputs = publicInputs // privateInputs; };
}
);
formatter = eachSystem (
{ pkgs, ... }:
(pkgs.callPackage ./formatter.nix { inputs = publicInputs // privateInputs; }).config.build.wrapper
);
packages = eachSystem (
{ pkgs, ... }:
{
fprint-supported-devices = pkgs.libfprint.overrideAttrs (old: {
nativeBuildInputs = old.nativeBuildInputs or [ ] ++ [
pkgs.jq
pkgs.gawk
];
buildPhase = ''
ninja libfprint/fprint-list-supported-devices
'';
outputs = [ "out" ];
installPhase = ''
./libfprint/fprint-list-supported-devices | \
grep -o -E '(\b[0-9a-fA-F]{4}:[0-9a-fA-F]{4}\b)' | \
awk '{print toupper($0)}' | \
jq -R -s 'split("\n") | map(select(. != "")) | map({key: ., value: true}) | from_entries' > $out
'';
# we cannot disable doInstallcheck because than we are missing nativeCheckInputs dependencies
installCheckPhase = "";
});
update-fprint-devices = pkgs.writeScriptBin "update-fprint-devices" ''
#!${pkgs.stdenv.shell}
target=$(git rev-parse --show-toplevel)/modules/nixos/fingerprint/devices.json
cat ${publicInputs.self.packages.${pkgs.system}.fprint-supported-devices} > "$target"
nix fmt -- "$target"
git add -- "$target"
'';
}
);
checks = eachSystem (
{ pkgs, ... }:
{
formatting =
(pkgs.callPackage ./formatter.nix { inputs = publicInputs // privateInputs; }).config.build.check
publicInputs.self;
minimal-machine =
(pkgs.nixos [
publicInputs.self.nixosModules.facter
(
{ lib, config, ... }:
{
boot.loader.grub.devices = lib.mkForce [ "/dev/sda" ];
fileSystems."/".device = lib.mkDefault "/dev/sda";
users.users.root.initialPassword = "fnord23";
system.stateVersion = config.system.nixos.version;
nixpkgs.pkgs = pkgs;
}
)
]).config.system.build.toplevel;
lib-tests = pkgs.runCommandLocal "lib-tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
export HOME="$(realpath .)"
export NIX_CONFIG='
extra-experimental-features = nix-command flakes
flake-registry = ""
'
nix-unit --expr '(import ${publicInputs.self}/lib { lib = import ${privateInputs.nixpkgs}/lib; }).tests'
touch $out
'';
}
);
};
}