-
-
Notifications
You must be signed in to change notification settings - Fork 203
/
flake.nix
155 lines (138 loc) · 4.78 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
153
154
155
{
description = "Disko - declarative disk partitioning";
# FIXME: in future we don't want lock here to give precedence to a USB live-installer's registry,
# but garnix currently does not allow this.
#inputs.nixpkgs.url = "nixpkgs";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
outputs = { self, nixpkgs, ... }:
let
lib = nixpkgs.lib;
supportedSystems = [
"x86_64-linux"
"i686-linux"
"aarch64-linux"
"riscv64-linux"
];
forAllSystems = lib.genAttrs supportedSystems;
versionInfo = import ./version.nix;
version = versionInfo.version + (lib.optionalString (!versionInfo.released) "-dirty");
diskoLib = import ./lib {
inherit (nixpkgs) lib;
};
in
{
nixosModules.default = self.nixosModules.disko; # convention
nixosModules.disko.imports = [ ./module.nix ];
lib = diskoLib;
packages = forAllSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
disko = pkgs.callPackage ./package.nix { diskoVersion = version; };
# alias to make `nix run` more convenient
disko-install = self.packages.${system}.disko.overrideAttrs (_old: {
name = "disko-install";
});
default = self.packages.${system}.disko;
create-release = pkgs.callPackage ./scripts/create-release.nix { };
} // pkgs.lib.optionalAttrs (!pkgs.stdenv.buildPlatform.isRiscV64) {
disko-doc = pkgs.callPackage ./doc.nix { };
});
# TODO: disable bios-related tests on aarch64...
# Run checks: nix flake check -L
checks = forAllSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
# FIXME: aarch64-linux seems to hang on boot
nixosTests = lib.optionalAttrs pkgs.stdenv.hostPlatform.isx86_64 (import ./tests {
inherit pkgs;
makeTest = import (pkgs.path + "/nixos/tests/make-test-python.nix");
eval-config = import (pkgs.path + "/nixos/lib/eval-config.nix");
});
disko-install = pkgs.callPackage ./tests/disko-install {
inherit self;
diskoVersion = version;
};
shellcheck = pkgs.runCommand "shellcheck" { nativeBuildInputs = [ pkgs.shellcheck ]; } ''
cd ${./.}
shellcheck disk-deactivate/disk-deactivate disko
touch $out
'';
jsonTypes = pkgs.writeTextFile { name = "jsonTypes"; text = (builtins.toJSON diskoLib.jsonTypes); };
in
# FIXME: aarch64-linux seems to hang on boot
lib.optionalAttrs pkgs.stdenv.hostPlatform.isx86_64 (nixosTests // { inherit disko-install; }) //
pkgs.lib.optionalAttrs (!pkgs.stdenv.buildPlatform.isRiscV64 && !pkgs.stdenv.hostPlatform.isx86_32) {
inherit shellcheck jsonTypes;
inherit (self.packages.${system}) disko-doc;
});
nixosConfigurations.testmachine = lib.nixosSystem {
system = "x86_64-linux";
modules = [
./tests/disko-install/configuration.nix
./example/hybrid.nix
./module.nix
];
};
formatter = forAllSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
pkgs.writeShellApplication {
name = "format";
runtimeInputs = with pkgs; [
nixpkgs-fmt
deno
deadnix
];
text = ''
showUsage() {
cat <<EOF
Usage: $0 [OPTIONS] FILES...
-c, --check Only check formatting, do not modify files.
-h, --help Show this help message.
EOF
}
check=
files=()
parseArgs() {
while [[ $# -gt 0 ]]; do
case "$1" in
-h | --help)
showUsage
exit 0
;;
-c | --check)
check=1
;;
*)
files+=("$1")
;;
esac
shift
done
if [[ ''${#files[@]} -eq 0 ]]; then
files=(.)
fi
}
main() {
parseArgs "$@"
if [[ -z "$check" ]]; then
set -o xtrace
nixpkgs-fmt -- "''${files[@]}"
deno fmt -- "''${files[@]}"
deadnix --edit -- "''${files[@]}"
else
set -o xtrace
nixpkgs-fmt --check -- "''${files[@]}"
deno fmt --check -- "''${files[@]}"
deadnix -- "''${files[@]}"
fi
}
main "$@"
'';
}
);
};
}