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