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