3 doom-emacs.follows = "julm-nix/doom-emacs";
4 home-manager.follows = "julm-nix/home-manager";
5 julm-nix.url = "git+file:///home/julm/work/sourcephile/nix/julm-nix?ref=main";
6 julm-nix.inputs.nixpkgs.follows = "nixpkgs";
7 nix-formatter-pack.follows = "julm-nix/nix-formatter-pack";
8 nixpkgs.url = "github:NixOS/nixpkgs/release-23.05";
9 pre-commit-hooks.follows = "julm-nix/pre-commit-hooks";
14 remoteNixpkgsPatches = import (inputs.julm-nix + "/nixpkgs/patches.nix");
15 localNixpkgsPatches = [
16 #nixpkgs/patches/systemd-coredump.diff
18 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
19 nixpkgsPath = originPkgs.applyPatches {
20 name = "nixpkgs-patched";
22 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
24 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
25 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
26 sort | sha256sum | cut -c -7)
27 echo "-patch-$patch" >.version-suffix
30 profile = "/nix/var/nix/profiles/system";
31 inherit (inputs.nixpkgs) lib;
32 #nixosSystem = lib.nixosSystem;
33 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
34 forAllSystems = f: lib.genAttrs lib.systems.flakeExposed (system: f rec {
36 #pkgs = inputs.nixpkgs.legacyPackages.${system};
37 pkgs = import nixpkgsPath {
40 import nixpkgs/overlays.nix ++
41 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
46 # nix -L build .#nixosConfigurations.mermet.config.system.build.toplevel
47 # nix -L build .#nixosConfigurations.mermet.config.boot.kernelPackages.kernel.configfile
48 # nix -L build .#nixosConfigurations.mermet.pkgs.hello
49 # nix eval --raw .#nixosConfigurations.mermet.config.networking.nftables.rulese
50 nixosConfigurations = lib.genAttrs
51 (builtins.attrNames (lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (inputs.self + "/hosts"))))
52 (hostName: nixosSystem
56 # Required to avoid infinite recursion
57 # when `inputs` is used in `imports`.
62 (inputs.self + "/hosts/${hostName}.nix")
66 hosts = inputs.self.nixosConfigurations;
67 host = inputs.self.nixosConfigurations.${hostName}._module.args;
70 import nixpkgs/overlays.nix ++
71 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
72 #nixpkgs.buildPlatform = "x86_64-linux";
73 nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ "hplip" ];
75 inputs.nixpkgs.nixosModules.notDetected
76 inputs.home-manager.nixosModules.home-manager
78 home-manager.useGlobalPkgs = true;
79 home-manager.useUserPackages = true;
80 home-manager.verbose = true;
81 home-manager.backupFileExtension = null;
82 home-manager.extraSpecialArgs = {
83 inherit hostName inputs;
87 programs.ssh.knownHosts = {
89 extraHostNames = [ "carotte" "carotte.sourcephile.fr" ];
90 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKnnS0w9zm5KuWwlfJu+qEXC0asESQySPp76szyMTE3J";
93 extraHostNames = [ "mermet" "mermet.sourcephile.fr" ];
94 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFvKN2sIpH782MFjaOpcty1Hs/T/TPNJpXI08H3O3oxl";
97 extraHostNames = [ "losurdo" "losurdo.sourcephile.fr" ];
98 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJkAq1T0Dxozt4RPylvWrUmeuejiG+n/owb3ucnWP9F";
106 # nix -L develop or direnv allow
107 devShell = forAllSystems ({ pkgs, system, ... }: pkgs.callPackage ./shell.nix
109 inherit pkgs inputs system nixpkgsPath;
110 inherit (inputs.self.checks.${system}.pre-commit-check) shellHook;
113 # nix -L run .#mermet.switch
114 apps = forAllSystems ({ pkgs, system, ... }:
117 (hostName: { config, ... }:
119 inherit (config.system) build;
120 target = "\"\${TARGET:-root@${config.networking.hostName}.${config.networking.domain}}\"";
121 scriptApp = scriptName: ps: script: {
123 program = (pkgs.writeShellScript "${hostName}-${scriptName}" ''
124 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
131 # Example: nix run .#mermet.switch
132 "switch" = scriptApp "switch" [ ] (''
136 chmod -R g-rwx,o-rwx **/*.gpg
137 trap 'git reset **/*.gpg' EXIT
138 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
140 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
141 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
143 nix copy --to ssh://${target}${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
145 # TODO: make it a LoadCredentialEncrypted= in nix-daemon.service
146 lib.optionalString config.boot.initrd.network.ssh.enable ''
147 # Send the SSH key of the initrd
148 gpg --decrypt 'hosts/${hostName}/ssh/initrd.key.gpg' |
149 ssh ${target} install -D -m 400 -o root -g root /dev/stdin /root/initrd/ssh.key
151 if ssh ${target} set -x ';' \
152 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
153 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
154 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
155 PATH=${with pkgs; lib.makeBinPath [ coreutils nix systemd ]}
157 ${profile}/bin/switch-to-configuration switch
160 ${build.toplevel}/bin/switch-to-configuration test
162 ssh ${target} -o ControlPath=none set -x ';' \
163 systemctl stop nixos-fallback.service ';' \
164 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
165 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
166 nix-env --delete-generations 7d --profile ${profile}
169 echo WARNING: switch-to-configuration was not registered at boot
171 ssh ${target} -o ControlPath=none set -x ';' \
172 systemctl stop nixos-fallback.service
176 # Example: nix run .#carotte.install-sd
177 # DELETEME: quite useless, better to use nixos-install
178 "install-sd" = scriptApp "install-sd" [ zstd ] ''
180 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.sdImage}
181 unzstd --stdout ${build.sdImage}/sd-image/*.img.zst |
182 sudo -k dd conv=notrunc oflag=direct,sync status=progress of="''${1:-/dev/mmcblk0}"
186 inputs.self.nixosConfigurations
190 checks = forAllSystems (args: with args; {
191 pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
194 nixpkgs-fmt.enable = true;
200 formatter = forAllSystems ({ pkgs, ... }:
201 inputs.nix-formatter-pack.lib.mkFormatter {
205 deadnix.enable = true;
206 nixpkgs-fmt.enable = true;
207 statix.enable = true;