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