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