]> Git — Sourcephile - sourcephile-nix.git/blob - flake.nix
nix: update flakes
[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/9031057b0e6642e61c74b3e3c97b4e80a8db1dd6";
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 = "path:julm-nix"; # FIXME: this puts the whole folder in the Nix store
8 inputs.julm-nix.inputs.flake-utils.follows = "flake-utils";
9 inputs.julm-nix.inputs.nixpkgs.follows = "nixpkgs";
10 inputs.shell = { type = "path"; path = "./shell"; flake = false; };
11 inputs.secrets = { type = "path"; path = "./sec"; flake = false; };
12 inputs.pass = { type = "path"; path = "./pass"; flake = false; };
13 outputs = inputs: let
14 remoteNixpkgsPatches = import nixpkgs/patches.nix;
15 localNixpkgsPatches = [
16 nixpkgs/patches/apparmor.diff
17 nixpkgs/patches/ifcopenshell.diff
18 nixpkgs/patches/public-inbox.diff
19 #nixpkgs/patches/zerobin.diff
20 #nixpkgs/patches/gitolite.diff
21 #nixpkgs/patches/tor.diff
22 #nixpkgs/patches/freeciv.diff
23 #nixpkgs/patches/fix-ld-nix.diff
24 #nixpkgs/patches/fix-ld-nix-apparmor.diff
25 ];
26 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
27 nixpkgs = originPkgs.applyPatches {
28 name = "nixpkgs-patched";
29 src = inputs.nixpkgs;
30 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
31 postPatch = ''
32 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
33 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
34 sort | sha256sum | cut -c -7)
35 echo "+patch-$patch" >.version-suffix
36 '';
37 };
38 lib = originPkgs.lib;
39 hosts = builtins.mapAttrs (hostName: hostConfig:
40 let cfg = import hostConfig { inherit inputs; }; in
41 import (nixpkgs + "/nixos/lib/eval-config.nix") (cfg // {
42 extraArgs = {
43 inherit hostName inputs;
44 hosts = inputs.self.nixosConfigurations;
45 host = inputs.self.nixosConfigurations.${hostName}.extraArgs;
46 } // (cfg.extraArgs or {});
47 modules = cfg.modules ++ [
48 inputs.home-manager.nixosModules.home-manager
49 {
50 home-manager.useGlobalPkgs = true;
51 home-manager.useUserPackages = true;
52 }
53 ({pkgs, ...}: {
54 nix.registry.nixpkgs.flake = nixpkgs;
55 nix.package = pkgs.nixUnstable;
56 nix.extraOptions = "experimental-features = nix-command flakes";
57 nixpkgs.overlays =
58 import nixpkgs/overlays.nix ++
59 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
60 system.nixos.versionSuffix = ".${
61 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
62 inputs.self.shortRev or "dirty"}";
63 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
64 # Let 'nixos-version --json' know about the Git revision of this flake.
65 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
66 boot.initrd.network.ssh.hostKeys = [ "/root/initrd/ssh.key" ];
67 security.gnupg.agent.enable = true;
68 security.gnupg.store = inputs.pass + "/hosts/${hostName}";
69 /*
70 system.configurationRevision =
71 if inputs.self ? rev
72 then inputs.self.rev
73 else throw "Refusing to build from a dirty Git tree!";
74 */
75 programs.ssh.knownHosts = {
76 mermet = {
77 hostNames = [ "mermet" "mermet.sourcephile.fr" ];
78 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFvKN2sIpH782MFjaOpcty1Hs/T/TPNJpXI08H3O3oxl";
79 };
80 losurdo = {
81 hostNames = [ "losurdo" "losurdo.sourcephile.fr" ];
82 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJkAq1T0Dxozt4RPylvWrUmeuejiG+n/owb3ucnWP9F";
83 };
84 };
85 })
86 ];
87 }));
88 in
89 {
90 # nix -L build .#nixosConfigurations.${hostName}.config.system.build.toplevel
91 nixosConfigurations = hosts {
92 losurdo = hosts/losurdo.nix;
93 mermet = hosts/mermet.nix;
94 };
95 #nixosModule = import nixos/modules.nix;
96 }
97 // inputs.flake-utils.lib.eachDefaultSystem (system:
98 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
99 let
100 pkgs = import nixpkgs {
101 inherit system;
102 overlays =
103 import nixpkgs/overlays.nix ++
104 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
105 };
106 in {
107 legacyPackages = pkgs;
108 devShell = import ./shell.nix { inherit inputs pkgs; };
109 apps = builtins.mapAttrs (hostName: { config, ... }: let
110 system = config.system.build.toplevel;
111 target = "root@${config.networking.hostName}.${config.networking.domain}";
112 profile = "/nix/var/nix/profiles/system";
113 in rec {
114 # Example: nix run .#losurdo.switch
115 "switch" = {
116 type = "app";
117 program = (pkgs.writeShellScript "switch" ''
118 set -eux
119 set -o pipefail
120 nix-store --add-root hosts/${hostName}.root --indirect --realise ${system}
121 nix copy --to ssh://'${target}' --substitute-on-destination ${system}
122 ${sendkeys.program}
123 # Send the SSH key of the initrd
124 gpg --decrypt '${config.security.gnupg.store}/initrd/ssh.key.gpg' |
125 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/ssh.key
126 # Send the Wireguard key of the initrd
127 gpg --decrypt '${config.security.gnupg.store}/wireguard/wg-intra/privateKey.gpg' |
128 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/wg-intra.key
129 ssh '${target}' \
130 nix-env --profile '${profile}' --set '${system}' '&&' \
131 '${profile}'/bin/switch-to-configuration switch
132 '').outPath;
133 };
134 # Example: nix run .#losurdo.sendkeys
135 "sendkeys" = {
136 type = "app";
137 #program = config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys";
138 program = (pkgs.writeShellScript "sendkeys" ''
139 set -eux
140 ${pkgs.bash}/bin/bash -eux ${config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys"}
141 '').outPath;
142 };
143 }) inputs.self.nixosConfigurations;}
144 );
145 }