]> Git — Sourcephile - sourcephile-nix.git/blob - flake.nix
nix: update to latest 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/b649c62cebed1eeb2f51275d72095a18916ecea3";
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://git.sourcephile.fr/julm/julm-nix?ref=master";
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 #nixpkgs/patches/transmission.diff
21 #nixpkgs/patches/apparmor.diff
22 #nixpkgs/patches/ifcopenshell.diff
23 #nixpkgs/patches/public-inbox.diff
24 #nixpkgs/patches/zerobin.diff
25 #nixpkgs/patches/gitolite.diff
26 #nixpkgs/patches/tor.diff
27 #nixpkgs/patches/freeciv.diff
28 #nixpkgs/patches/fix-ld-nix.diff
29 #nixpkgs/patches/fix-ld-nix-apparmor.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; }; in
46 import (nixpkgs + "/nixos/lib/eval-config.nix") (cfg // {
47 extraArgs = {
48 inherit hostName inputs;
49 hosts = inputs.self.nixosConfigurations;
50 host = inputs.self.nixosConfigurations.${hostName}.extraArgs;
51 } // (cfg.extraArgs or {});
52 modules = cfg.modules ++ [
53 inputs.home-manager.nixosModules.home-manager
54 {
55 home-manager.useGlobalPkgs = true;
56 home-manager.useUserPackages = true;
57 home-manager.verbose = true;
58 home-manager.backupFileExtension = null;
59 home-manager.extraSpecialArgs = {
60 inherit hostName;
61 };
62 }
63 ({pkgs, ...}: {
64 nix.registry.nixpkgs.flake = nixpkgs;
65 nix.package = pkgs.nixUnstable;
66 nix.extraOptions = "experimental-features = nix-command flakes";
67 nixpkgs.overlays =
68 import nixpkgs/overlays.nix ++
69 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
70 system.nixos.versionSuffix = ".${
71 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
72 inputs.self.shortRev or "dirty"}";
73 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
74 # Let 'nixos-version --json' know about the Git revision of this flake.
75 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
76 boot.initrd.network.ssh.hostKeys = [ "/root/initrd/ssh.key" ];
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 mermet = {
87 hostNames = [ "mermet" "mermet.sourcephile.fr" ];
88 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFvKN2sIpH782MFjaOpcty1Hs/T/TPNJpXI08H3O3oxl";
89 };
90 losurdo = {
91 hostNames = [ "losurdo" "losurdo.sourcephile.fr" ];
92 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJkAq1T0Dxozt4RPylvWrUmeuejiG+n/owb3ucnWP9F";
93 };
94 };
95 })
96 ];
97 }));
98 in
99 {
100 # nix -L build .#nixosConfigurations.${hostName}.config.system.build.toplevel
101 nixosConfigurations = hosts {
102 losurdo = hosts/losurdo.nix;
103 mermet = hosts/mermet.nix;
104 };
105 #nixosModule = import nixos/modules.nix;
106 }
107 // inputs.flake-utils.lib.eachDefaultSystem (system:
108 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
109 let
110 pkgs = import nixpkgs {
111 inherit system;
112 overlays =
113 import nixpkgs/overlays.nix ++
114 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
115 };
116 in {
117 legacyPackages = pkgs;
118 devShell = import ./shell.nix { inherit inputs pkgs; };
119 apps = builtins.mapAttrs (hostName: { config, ... }: let
120 system = config.system.build.toplevel;
121 target = "root@${config.networking.hostName}.${config.networking.domain}";
122 profile = "/nix/var/nix/profiles/system";
123 in rec {
124 # Example: nix run .#losurdo.switch
125 "switch" = {
126 type = "app";
127 program = (pkgs.writeShellScript "switch" ''
128 set -eux
129 set -o pipefail
130 nix-store --add-root hosts/${hostName}.root --indirect --realise ${system}
131 nix copy --to ssh://'${target}' --substitute-on-destination ${system}
132 ${sendkeys.program}
133 # Send the SSH key of the initrd
134 gpg --decrypt '${config.security.gnupg.store}/initrd/ssh.key.gpg' |
135 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/ssh.key
136 # Send the Wireguard key of the initrd
137 gpg --decrypt '${config.security.gnupg.store}/wireguard/wg-intra/privateKey.gpg' |
138 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/wg-intra.key
139 ssh '${target}' \
140 nix-env --profile '${profile}' --set '${system}' '&&' \
141 '${profile}'/bin/switch-to-configuration switch
142 '').outPath;
143 };
144 # Example: nix run .#losurdo.sendkeys
145 "sendkeys" = {
146 type = "app";
147 #program = config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys";
148 program = (pkgs.writeShellScript "sendkeys" ''
149 set -eux
150 ${pkgs.bash}/bin/bash -eux ${config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys"}
151 '').outPath;
152 };
153 }) inputs.self.nixosConfigurations;}
154 );
155 }