]> Git — Sourcephile - sourcephile-nix.git/blob - flake.nix
linux: fbcon=rotate_all does not work as kernel parameter
[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/aee78d463e826ea5c144cff9c8e9e8c02a6ea4a0";
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.agent.enable = true;
54 security.gnupg.store = inputs.pass + "/machines/${machineName}";
55 /*
56 system.configurationRevision =
57 if inputs.self ? rev
58 then inputs.self.rev
59 else throw "Refusing to build from a dirty Git tree!";
60 */
61 programs.ssh.knownHosts = {
62 mermet = {
63 hostNames = [ "mermet" "mermet.sourcephile.fr" ];
64 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFvKN2sIpH782MFjaOpcty1Hs/T/TPNJpXI08H3O3oxl";
65 };
66 losurdo = {
67 hostNames = [ "losurdo" "losurdo.sourcephile.fr" ];
68 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJkAq1T0Dxozt4RPylvWrUmeuejiG+n/owb3ucnWP9F";
69 };
70 };
71 })];
72 }));
73 in
74 {
75 # nix -L build .#nixosConfigurations.${machineName}.config.system.build.toplevel
76 nixosConfigurations = machines {
77 losurdo = machines/losurdo.nix;
78 mermet = machines/mermet.nix;
79 };
80 #nixosModule = import nixos/modules.nix;
81 }
82 // inputs.flake-utils.lib.eachDefaultSystem (system:
83 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
84 let
85 pkgs = import nixpkgs {
86 inherit system;
87 overlays = import nixpkgs/overlays.nix;
88 };
89 in {
90 legacyPackages = pkgs;
91 devShell = import ./shell.nix { inherit inputs pkgs; };
92 apps = builtins.mapAttrs (machineName: { config, ... }: let
93 system = config.system.build.toplevel;
94 target = "root@${config.networking.hostName}.${config.networking.domain}";
95 profile = "/nix/var/nix/profiles/system";
96 in rec {
97 # Example: nix run .#losurdo.switch
98 "switch" = {
99 type = "app";
100 program = (pkgs.writeShellScript "switch" ''
101 set -eux
102 set -o pipefail
103 nix-store --add-root machines/${machineName}.root --indirect --realise ${system}
104 nix copy --to ssh://'${target}' --substitute-on-destination ${system}
105 ${sendkeys.program}
106 # Send the SSH key of the initrd
107 gpg --decrypt '${config.security.gnupg.store}/initrd/ssh.key.gpg' |
108 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/ssh.key
109 # Send the Wireguard key of the initrd
110 gpg --decrypt '${config.security.gnupg.store}/wireguard/wg-intra/privateKey.gpg' |
111 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/wg-intra.key
112 ssh '${target}' \
113 nix-env --profile '${profile}' --set '${system}' '&&' \
114 '${profile}'/bin/switch-to-configuration switch
115 '').outPath;
116 };
117 # Example: nix run .#losurdo.sendkeys
118 "sendkeys" = {
119 type = "app";
120 program = config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys";
121 };
122 }) inputs.self.nixosConfigurations;}
123 );
124 }