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