]> Git — Sourcephile - sourcephile-nix.git/blob - flake.nix
nix: update patches and wip stuffs
[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/6b342809b1b66dce758364f763b64c6a1a9e6211";
4 #inputs.nixpkgs.url = "flake:nixpkgs";
5 inputs.flake-utils.url = "github:numtide/flake-utils";
6 inputs.shell = { type = "path"; path = "./shell"; flake = false; };
7 inputs.secrets = { type = "path"; path = "./sec"; flake = false; };
8 inputs.pass = { type = "path"; path = "./pass"; flake = false; };
9 outputs = inputs: let
10 remoteNixpkgsPatches = import nixpkgs/patches.nix;
11 localNixpkgsPatches = [
12 nixpkgs/patches/apparmor.diff
13 #nixpkgs/patches/public-inbox.diff
14 #nixpkgs/patches/zerobin.diff
15 #nixpkgs/patches/gitolite.diff
16 #nixpkgs/patches/tor.diff
17 #nixpkgs/patches/freeciv.diff
18 #nixpkgs/patches/fix-ld-nix.diff
19 #nixpkgs/patches/fix-ld-nix-apparmor.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 machines = builtins.mapAttrs (machineName: machineConfig:
35 let cfg = import machineConfig { inherit inputs; }; in
36 import (nixpkgs + "/nixos/lib/eval-config.nix") (cfg // {
37 extraArgs = {
38 inherit machineName inputs;
39 machines = inputs.self.nixosConfigurations;
40 } // (cfg.extraArgs or {});
41 modules = cfg.modules ++ [({pkgs, ...}: {
42 nix.registry.nixpkgs.flake = nixpkgs;
43 nix.package = pkgs.nixUnstable;
44 nix.extraOptions = "experimental-features = nix-command flakes";
45 nixpkgs.overlays = import nixpkgs/overlays.nix;
46 system.nixos.versionSuffix = ".${
47 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
48 inputs.self.shortRev or "dirty"}";
49 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
50 # Let 'nixos-version --json' know about the Git revision of this flake.
51 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
52 boot.initrd.network.ssh.hostKeys = [ "/root/initrd/ssh.key" ];
53 security.gnupg.store = inputs.pass + "/machines/${machineName}";
54 /*
55 system.configurationRevision =
56 if inputs.self ? rev
57 then inputs.self.rev
58 else throw "Refusing to build from a dirty Git tree!";
59 */
60 programs.ssh.knownHosts = {
61 mermet = {
62 hostNames = [ "mermet" "mermet.sourcephile.fr" ];
63 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFvKN2sIpH782MFjaOpcty1Hs/T/TPNJpXI08H3O3oxl";
64 };
65 losurdo = {
66 hostNames = [ "losurdo" "losurdo.sourcephile.fr" ];
67 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJkAq1T0Dxozt4RPylvWrUmeuejiG+n/owb3ucnWP9F";
68 };
69 };
70 })];
71 }));
72 in
73 {
74 # nix -L build .#nixosConfigurations.${machineName}.config.system.build.toplevel
75 nixosConfigurations = machines {
76 losurdo = machines/losurdo.nix;
77 mermet = machines/mermet.nix;
78 };
79 #nixosModule = import nixos/modules.nix;
80 }
81 // inputs.flake-utils.lib.eachDefaultSystem (system:
82 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
83 let
84 pkgs = import nixpkgs {
85 inherit system;
86 overlays = import nixpkgs/overlays.nix;
87 };
88 in {
89 legacyPackages = pkgs;
90 devShell = import ./shell.nix { inherit inputs pkgs; };
91 apps = builtins.mapAttrs (machineName: { config, ... }: let
92 system = config.system.build.toplevel;
93 keygrip = builtins.getAttr machineName {
94 losurdo = "9AA84E6F6D71F9163C46BF396B141A0806219077";
95 mermet = "89F52A879E0019A966503AFFDE72EEA84CDFA3A7";
96 };
97 target = "root@${config.networking.hostName}.${config.networking.domain}";
98 profile = "/nix/var/nix/profiles/system";
99 in rec {
100 # Example: nix run .#losurdo.switch
101 "switch" = {
102 type = "app";
103 program = (pkgs.writeShellScript "switch" ''
104 set -eux
105 set -o pipefail
106 nix-store --add-root machines/${machineName}.root --indirect --realise ${system}
107 nix copy --to ssh://'${target}' --substitute-on-destination ${system}
108 ${sendkeys.program}
109 # Send the SSH key of the initrd
110 gpg --decrypt '${config.security.gnupg.store}/initrd/ssh.key.gpg' |
111 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/ssh.key
112 # Send the Wireguard key of the initrd
113 gpg --decrypt '${config.security.gnupg.store}/wireguard/wg-intra/privateKey.gpg' |
114 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/wg-intra.key
115 ssh '${target}' \
116 nix-env --profile '${profile}' --set '${system}' '&&' \
117 '${profile}'/bin/switch-to-configuration switch
118 '').outPath;
119 };
120 # Example: nix run .#losurdo.sendkeys
121 "sendkeys" = {
122 type = "app";
123 program = config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys";
124 };
125 }) inputs.self.nixosConfigurations;}
126 );
127 }