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