]> Git — Sourcephile - sourcephile-nix.git/blob - flake.nix
nix: update nixpkgs
[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/62ca4a425ab112e5d8a75682ee76c069cdb42d4b";
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 = "path:julm-nix"; # XXX: this puts the whole folder in the Nix store
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 outputs = inputs: let
17 remoteNixpkgsPatches = import nixpkgs/patches.nix;
18 localNixpkgsPatches = [
19 nixpkgs/patches/sourcehut.diff
20 ];
21 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
22 nixpkgs = originPkgs.applyPatches {
23 name = "nixpkgs-patched";
24 src = inputs.nixpkgs;
25 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
26 postPatch = ''
27 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
28 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
29 sort | sha256sum | cut -c -7)
30 echo "+patch-$patch" >.version-suffix
31 '';
32 };
33 lib = originPkgs.lib;
34 hosts = builtins.mapAttrs (hostName: hostConfig:
35 let cfg = import hostConfig { inherit inputs; }; in
36 import (nixpkgs + "/nixos/lib/eval-config.nix") (cfg // {
37 extraArgs = {
38 inherit hostName inputs;
39 hosts = inputs.self.nixosConfigurations;
40 host = inputs.self.nixosConfigurations.${hostName}.extraArgs;
41 } // (cfg.extraArgs or {});
42 modules = cfg.modules ++ [
43 inputs.home-manager.nixosModules.home-manager
44 {
45 home-manager.useGlobalPkgs = true;
46 home-manager.useUserPackages = true;
47 home-manager.verbose = true;
48 home-manager.backupFileExtension = null;
49 home-manager.extraSpecialArgs = {
50 inherit hostName;
51 };
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 # Example: nix -L build .#nixosConfigurations.losurdo.config.system.build.toplevel
91 # Example: nix eval .#nixosConfigurations.losurdo.config.networking.hostName
92 nixosConfigurations = hosts {
93 losurdo = hosts/losurdo.nix;
94 mermet = hosts/mermet.nix;
95 };
96 #nixosModule = import nixos/modules.nix;
97 }
98 // inputs.flake-utils.lib.eachDefaultSystem (system:
99 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
100 let
101 pkgs = import nixpkgs {
102 inherit system;
103 overlays =
104 import nixpkgs/overlays.nix ++
105 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
106 };
107 in {
108 legacyPackages = pkgs;
109 devShell = import ./shell.nix { inherit inputs pkgs; };
110 apps = builtins.mapAttrs (hostName: { config, ... }: let
111 system = config.system.build.toplevel;
112 target = "root@${config.networking.hostName}.${config.networking.domain}";
113 profile = "/nix/var/nix/profiles/system";
114 in rec {
115 # Example: nix run .#losurdo.switch
116 "switch" = {
117 type = "app";
118 program = (pkgs.writeShellScript "switch" ''
119 set -eux
120 set -o pipefail
121 nix-store --add-root hosts/${hostName}.root --indirect --realise ${system}
122 nix copy --to ssh://'${target}' --substitute-on-destination ${system}
123 ${sendkeys.program}
124 # Send the SSH key of the initrd
125 gpg --decrypt '${config.security.gnupg.store}/initrd/ssh.key.gpg' |
126 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/ssh.key
127 # Send the Wireguard key of the initrd
128 gpg --decrypt '${config.security.gnupg.store}/wireguard/wg-intra/privateKey.gpg' |
129 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/wg-intra.key
130 ssh '${target}' \
131 nix-env --profile '${profile}' --set '${system}' '&&' \
132 '${profile}'/bin/switch-to-configuration switch
133 '').outPath;
134 };
135 # Example: nix run .#losurdo.sendkeys
136 "sendkeys" = {
137 type = "app";
138 #program = config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys";
139 program = (pkgs.writeShellScript "sendkeys" ''
140 set -eux
141 ${pkgs.bash}/bin/bash -eux ${config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys"}
142 '').outPath;
143 };
144 }) inputs.self.nixosConfigurations;}
145 );
146 }