]> Git — Sourcephile - sourcephile-nix.git/blob - flake.nix
nix: fix dependencies
[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 = "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.shell = { type = "path"; path = "./shell"; flake = false; };
12 inputs.secrets = { type = "path"; path = "./sec"; flake = false; };
13 inputs.pass = { type = "path"; path = "./pass"; flake = false; };
14 outputs = inputs: let
15 remoteNixpkgsPatches = import nixpkgs/patches.nix;
16 localNixpkgsPatches = [
17 nixpkgs/patches/apparmor.diff
18 #nixpkgs/patches/ifcopenshell.diff
19 #nixpkgs/patches/public-inbox.diff
20 #nixpkgs/patches/zerobin.diff
21 #nixpkgs/patches/gitolite.diff
22 #nixpkgs/patches/tor.diff
23 #nixpkgs/patches/freeciv.diff
24 #nixpkgs/patches/fix-ld-nix.diff
25 #nixpkgs/patches/fix-ld-nix-apparmor.diff
26 ];
27 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
28 nixpkgs = originPkgs.applyPatches {
29 name = "nixpkgs-patched";
30 src = inputs.nixpkgs;
31 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
32 postPatch = ''
33 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
34 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
35 sort | sha256sum | cut -c -7)
36 echo "+patch-$patch" >.version-suffix
37 '';
38 };
39 lib = originPkgs.lib;
40 hosts = builtins.mapAttrs (hostName: hostConfig:
41 let cfg = import hostConfig { inherit inputs; }; in
42 import (nixpkgs + "/nixos/lib/eval-config.nix") (cfg // {
43 extraArgs = {
44 inherit hostName inputs;
45 hosts = inputs.self.nixosConfigurations;
46 host = inputs.self.nixosConfigurations.${hostName}.extraArgs;
47 } // (cfg.extraArgs or {});
48 modules = cfg.modules ++ [
49 inputs.home-manager.nixosModules.home-manager
50 {
51 home-manager.useGlobalPkgs = true;
52 home-manager.useUserPackages = true;
53 }
54 ({pkgs, ...}: {
55 nix.registry.nixpkgs.flake = nixpkgs;
56 nix.package = pkgs.nixUnstable;
57 nix.extraOptions = "experimental-features = nix-command flakes";
58 nixpkgs.overlays =
59 import nixpkgs/overlays.nix ++
60 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
61 system.nixos.versionSuffix = ".${
62 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
63 inputs.self.shortRev or "dirty"}";
64 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
65 # Let 'nixos-version --json' know about the Git revision of this flake.
66 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
67 boot.initrd.network.ssh.hostKeys = [ "/root/initrd/ssh.key" ];
68 security.gnupg.agent.enable = true;
69 security.gnupg.store = inputs.pass + "/hosts/${hostName}";
70 /*
71 system.configurationRevision =
72 if inputs.self ? rev
73 then inputs.self.rev
74 else throw "Refusing to build from a dirty Git tree!";
75 */
76 programs.ssh.knownHosts = {
77 mermet = {
78 hostNames = [ "mermet" "mermet.sourcephile.fr" ];
79 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFvKN2sIpH782MFjaOpcty1Hs/T/TPNJpXI08H3O3oxl";
80 };
81 losurdo = {
82 hostNames = [ "losurdo" "losurdo.sourcephile.fr" ];
83 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJkAq1T0Dxozt4RPylvWrUmeuejiG+n/owb3ucnWP9F";
84 };
85 };
86 })
87 ];
88 }));
89 in
90 {
91 # nix -L build .#nixosConfigurations.${hostName}.config.system.build.toplevel
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 }