-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflake.nix
156 lines (150 loc) · 5.51 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
156
{
description = "My nixos config";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
unstable-pkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixos-facter-modules.url = "github:numtide/nixos-facter-modules";
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
nur = {
url = "github:nix-community/NUR";
inputs.nixpkgs.follows = "nixpkgs";
};
sops = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager = {
url = "github:nix-community/home-manager/release-24.11";
inputs.nixpkgs.follows = "nixpkgs";
};
catppuccin = {
url = "github:catppuccin/nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, sops, nur, home-manager, disko, catppuccin, ... }@inputs:
let
system = "x86_64-linux";
filterAttr = f: attrs:
let
names = with builtins; (filter (key: f key (getAttr key attrs)) (attrNames attrs));
in
with builtins;
foldl' (set: name: set // { "${name}" = getAttr name attrs; }) { } names;
machine-files = with builtins; attrNames (filterAttr (f: t: t == "regular") (readDir ./machines));
nix-machine-files = with builtins; filter
(n:
let
len = builtins.stringLength n;
in
builtins.substring (len - 4) len n == ".nix")
machine-files;
targets = with builtins; map
(n:
let
len = builtins.stringLength n;
in
builtins.substring 0 (len - 4) n)
nix-machine-files;
pkgs = import nixpkgs { inherit system; };
unstable = import inputs.unstable-pkgs { inherit system; config.allowUnfree = true; };
xadetPackages = import ./packages { inherit pkgs self disko system targets; };
nixosMachine = configFile: nixpkgs.lib.nixosSystem rec {
inherit system;
modules = [
{
nixpkgs.overlays = [
(final: prev: xadetPackages)
(final: prev: { inherit unstable inputs system; })
(final: prev: {
candle = prev.candle.overrideAttrs (oldAttrs: rec {
version = "1.2b";
src = pkgs.fetchFromGitHub {
owner = "Denvi";
repo = "Candle";
rev = "v${version}";
sha256 = "sha256-+14ZRFtAo+WzM4v3U3l9uU3xzhzbdM8+iaujhz9dNuY=";
};
cmakeFlags = [
"-DDEFAULT_SETTINGS_LOCATION=ON"
];
});
})
];
}
home-manager.nixosModules.home-manager
disko.nixosModules.disko
sops.nixosModules.sops
nur.modules.nixos.default
catppuccin.nixosModules.catppuccin
nur.legacyPackages."${system}".repos.iopq.modules.xraya
inputs.nixos-facter-modules.nixosModules.facter
"${./.}/machines/${configFile}.nix"
./modules
{
options = {
usedFlake = pkgs.lib.mkOption {
type = pkgs.lib.types.str;
default = "${configFile}";
};
};
}
];
};
in
{
packages."${system}" = xadetPackages;
apps."${system}" = {
create-install-usb =
let
rootUsbScript = pkgs.writeShellScriptBin "root-iso-to-usb" ''
set -e
TARGET_DEVICE="$1"
ISO_SIZE=$(wc -c "${self.installIso}/iso/${self.installIso.isoName}")
echo "Going to write $ISO_SIZE bytes to the USB stick at $TARGET_DEVICE"
${pkgs.util-linux}/bin/wipefs --all "$TARGET_DEVICE"
dd if=${self.installIso}/iso/${self.installIso.isoName} of="$TARGET_DEVICE" status=progress
'';
usbScript = pkgs.writeShellScriptBin "iso-to-usb" ''
set -e
if [ "$#" -ne 1 ]; then
echo "Usage : $0 /dev/selected_mass_storage" >&2
echo "with /dev/selected_mass_storage being the raw device (and not a partition) for a USB stick on which to install the vault live image" >&2
exit -1
fi
KEY="$1"
if [ "$(<''${KEY/dev/sys\/block}/removable)" != "1" ]; then
echo "Error : $KEY is not removable." >&2
exit -2
fi
read -p "Make sure all partitions on destination device $KEY are unmounted then press enter" answer
if [[ -n $(${pkgs.util-linux}/bin/lsblk -n -o MOUNTPOINTS $KEY) ]]; then
echo "Some partitions are still mounted. Please unmount them."
${pkgs.util-linux}/bin/lsblk $KEY
exit -3
fi
sudo ${pkgs.lib.getExe rootUsbScript} $KEY
'';
in
{
type = "app";
program = "${pkgs.lib.getExe usbScript}";
};
};
devShells."${system}".default = pkgs.mkShell {
packages = [
pkgs.sops
pkgs.age
];
shellHook = ''
export SOPS_AGE_KEY_FILE="''$(pwd)/keys/ageKey.txt";
'';
};
installIso = import ./install/iso.nix (inputs // { inherit system pkgs targets; });
testInstallIso = import ./install/testIso.nix { inherit pkgs self; };
nixosConfigurations = builtins.foldl' (set: name: set // { "${name}" = nixosMachine "${name}"; }) { } targets;
};
}