]> Git — Sourcephile - sourcephile-nix.git/blob - flake.nix
losurdo: try to fix hostapd config
[sourcephile-nix.git] / flake.nix
1 {
2 # Pin down nixpkgs from github, instead of using global, system or user registries.
3 inputs.nixpkgs.url = "github:NixOS/nixpkgs/5cf90a60e5ddf68fbfc04d643970136bf00ba315";
4 #inputs.nixpkgs.url = "flake:nixpkgs";
5 inputs.flake-utils.url = "github:numtide/flake-utils";
6 inputs.home-manager.follows = "julm-nix/home-manager";
7 #inputs.julm-nix.url = "git+https://git.hut.sourcephile.fr/~julm/julm-nix?ref=main";
8 inputs.julm-nix.url = "git+file:///home/julm/work/sourcephile/nix/julm-nix?ref=main";
9 inputs.julm-nix.inputs.flake-utils.follows = "flake-utils";
10 inputs.julm-nix.inputs.nixpkgs.follows = "nixpkgs";
11 inputs.doom-emacs.follows = "julm-nix/doom-emacs";
12 inputs.nix-doom-emacs.follows = "julm-nix/nix-doom-emacs";
13 inputs.nix-doom-emacs.inputs.doom-emacs.follows = "julm-nix/doom-emacs";
14 inputs.emacs-overlay.follows = "julm-nix/emacs-overlay";
15 #inputs.shell = { type = "path"; path = "./shell"; flake = false; };
16 #inputs.secrets = { type = "path"; path = "./sec"; flake = false; };
17 #inputs.pass = { type = "path"; path = "./pass"; flake = false; };
18 inputs.shell.url = "path:./shell";
19 inputs.shell.flake = false;
20 inputs.secrets.type = "path";
21 inputs.secrets.path = "/home/julm/work/sourcephile/nix/sec";
22 inputs.secrets.flake = false;
23 inputs.pass.type = "path";
24 inputs.pass.path = "/home/julm/work/sourcephile/nix/pass";
25 inputs.pass.flake = false;
26
27 outputs = inputs: let
28 remoteNixpkgsPatches = import nixpkgs/patches.nix;
29 localNixpkgsPatches = [
30 nixpkgs/patches/sourcehut.diff
31 nixpkgs/patches/systemd-coredump.diff
32 ];
33 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
34 nixpkgsPath = originPkgs.applyPatches {
35 name = "nixpkgs-patched";
36 src = inputs.nixpkgs;
37 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
38 postPatch = ''
39 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
40 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
41 sort | sha256sum | cut -c -7)
42 echo "+patch-$patch" >.version-suffix
43 '';
44 };
45 lib = originPkgs.lib;
46 hosts = builtins.mapAttrs (hostName: hostConfig:
47 let cfg = import hostConfig { inherit inputs hostName nixpkgsPath; }; in
48 import (nixpkgsPath + "/nixos/lib/eval-config.nix") (lib.recursiveUpdate cfg {
49 specialArgs = {
50 inherit hostName inputs;
51 private = "/root/private"; # Kept out of /nix/store
52 };
53 modules = cfg.modules ++ [
54 {
55 config._module.args = {
56 hosts = inputs.self.nixosConfigurations;
57 host = inputs.self.nixosConfigurations.${hostName}._module.args;
58 };
59 }
60 inputs.home-manager.nixosModules.home-manager
61 {
62 home-manager.useGlobalPkgs = true;
63 home-manager.useUserPackages = true;
64 home-manager.verbose = true;
65 home-manager.backupFileExtension = null;
66 home-manager.extraSpecialArgs = {
67 inherit hostName inputs;
68 };
69 }
70 ({ pkgs, ... }: {
71 nix.package = pkgs.nixUnstable;
72 nixpkgs.overlays =
73 import nixpkgs/overlays.nix ++
74 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
75 system.nixos.versionSuffix = ".${
76 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
77 inputs.self.shortRev or "dirty"}";
78 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
79 # Let 'nixos-version --json' know about the Git revision of this flake.
80 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
81 security.gnupg.agent.enable = true;
82 security.gnupg.store = inputs.pass + "/hosts/${hostName}";
83 /*
84 system.configurationRevision =
85 if inputs.self ? rev
86 then inputs.self.rev
87 else throw "Refusing to build from a dirty Git tree!";
88 */
89 programs.ssh.knownHosts = {
90 carotte = {
91 hostNames = [ "carotte" "carotte.sourcephile.fr" ];
92 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKnnS0w9zm5KuWwlfJu+qEXC0asESQySPp76szyMTE3J";
93 };
94 mermet = {
95 hostNames = [ "mermet" "mermet.sourcephile.fr" ];
96 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFvKN2sIpH782MFjaOpcty1Hs/T/TPNJpXI08H3O3oxl";
97 };
98 losurdo = {
99 hostNames = [ "losurdo" "losurdo.sourcephile.fr" ];
100 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJkAq1T0Dxozt4RPylvWrUmeuejiG+n/owb3ucnWP9F";
101 };
102 };
103 })
104 ];
105 }));
106 in
107 {
108 # Example: nix -L build .#nixosConfigurations.losurdo.config.system.build.toplevel
109 # Example: nix -L build .#nixosConfigurations.losurdo.config.boot.kernelPackages.kernel.configfile
110 # Example: nix -L build .#nixosConfigurations.losurdo.pkgs.hello
111 # Example: nix eval .#nixosConfigurations.losurdo.config.networking.hostName
112 nixosConfigurations = hosts {
113 carotte = hosts/carotte.nix;
114 losurdo = hosts/losurdo.nix;
115 mermet = hosts/mermet.nix;
116 };
117 #nixosModule = import nixos/modules.nix;
118 }
119 // inputs.flake-utils.lib.eachDefaultSystem (system:
120 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
121 let
122 pkgs = import nixpkgsPath {
123 inherit system;
124 overlays =
125 import nixpkgs/overlays.nix ++
126 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
127 };
128 in {
129 legacyPackages = pkgs;
130 devShell = import ./shell.nix { inherit inputs pkgs; };
131 apps = builtins.mapAttrs (hostName: { config, ... }: let
132 build = config.system.build;
133 target = "\"\${TARGET:-root@${config.networking.hostName}.${config.networking.domain}}\"";
134 profile = "/nix/var/nix/profiles/system";
135 in rec {
136 # Example: nix run .#losurdo.switch
137 "switch" = {
138 type = "app";
139 program = (pkgs.writeShellScript "switch" (''
140 set -eux
141 set -o pipefail
142 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
143 nix copy --to ssh://${target} --substitute-on-destination ${build.toplevel}
144 ${sendkeys.program}
145 '' + lib.optionalString config.boot.initrd.network.ssh.enable ''
146 # Send the SSH key of the initrd
147 gpg --decrypt '${config.security.gnupg.store}/initrd/ssh.key.gpg' |
148 ssh ${target} install -D -m 400 -o root -g root /dev/stdin /root/initrd/ssh.key
149 # Send the Wireguard key of the initrd
150 gpg --decrypt '${config.security.gnupg.store}/wireguard/wg-intra/privateKey.gpg' |
151 ssh ${target} install -D -m 400 -o root -g root /dev/stdin /root/initrd/wg-intra.key
152 '' + ''
153 ssh ${target} \
154 nix-env --profile '${profile}' --set '${build.toplevel}' '&&' \
155 '${profile}'/bin/switch-to-configuration switch
156 ''
157 )).outPath;
158 };
159 # Example: nix run .#carotte.install-sd
160 "install-sd" = {
161 type = "app";
162 program = (pkgs.writeShellScript "install-sd" ''
163 export PATH="$PATH:${with pkgs; lib.makeBinPath [coreutils zstd]}"
164 set -eux
165 set -o pipefail
166 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.sdImage}
167 unzstd --stdout ${build.sdImage}/sd-image/*.img.zst |
168 sudo -k dd conv=notrunc oflag=direct,sync status=progress of="''${1:-/dev/mmcblk0}"
169 '').outPath;
170 };
171 # Example: nix run .#losurdo.sendkeys
172 "sendkeys" = {
173 type = "app";
174 #program = config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys";
175 program = (pkgs.writeShellScript "sendkeys" ''
176 set -eux
177 ${pkgs.bash}/bin/bash -eux ${config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys"}
178 '').outPath;
179 };
180 }) inputs.self.nixosConfigurations;}
181 );
182 }