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 nixpkgs.follows = "julm-nix/nixpkgs";
7 git-hooks.follows = "julm-nix/git-hooks";
13 remoteNixpkgsPatches = import (inputs.julm-nix + "/nixpkgs/patches.nix");
14 localNixpkgsPatches = [
15 #nixpkgs/patches/systemd-coredump.diff
16 "${inputs.julm-nix}/nixpkgs/patches/openvpn/0001-nixos-netns-init-module-to-manage-network-namespaces.patch"
17 "${inputs.julm-nix}/nixpkgs/patches/openvpn/0002-nixos-openvpn-add-netns-support.patch"
18 "${inputs.julm-nix}/nixpkgs/patches/syncoid/0001-nixos-sanoid-add-utilities-useful-to-syncoid.patch"
19 "${inputs.julm-nix}/nixpkgs/patches/syncoid/0002-nixos-syncoid-use-DynamicUser.patch"
21 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
22 nixpkgsPath = originPkgs.applyPatches {
23 name = "nixpkgs-patched";
25 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
27 patch=$(printf '%s\n' ${
28 builtins.concatStringsSep " " (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)
30 sort | sha256sum | cut -c -7)
31 echo "-patch-$patch" >.version-suffix
34 profile = "/nix/var/nix/profiles/system";
35 inherit (inputs.nixpkgs) lib;
39 (finalPkgs: previousPkgs: { })
41 ++ import (inputs.julm-nix + "/nixpkgs/overlays.nix")
42 ++ import nixpkgs/overlays.nix;
43 #nixosSystem = lib.nixosSystem;
44 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
47 lib.genAttrs lib.systems.flakeExposed (
51 #pkgs = inputs.nixpkgs.legacyPackages.${system};
52 pkgs = import nixpkgsPath {
54 overlays = overlays system;
60 # nix -L build .#hello
61 packages = forAllSystems (args: with args; pkgs);
63 # nix -L build .#nixosConfigurations.mermet.config.system.build.toplevel
64 # nix -L build .#nixosConfigurations.mermet.config.boot.kernelPackages.kernel.configfile
65 # nix -L build .#nixosConfigurations.mermet.pkgs.hello
66 # nix eval --raw .#nixosConfigurations.mermet.config.networking.nftables.ruleset
70 lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (inputs.self + "/hosts"))
77 # Required to avoid infinite recursion
78 # when `inputs` is used in `imports`.
83 (inputs.julm-nix + "/nixos/default.nix")
84 (inputs.self + "/hosts/${hostName}.nix")
90 hosts = inputs.self.nixosConfigurations;
91 host = inputs.self.nixosConfigurations.${hostName}._module.args;
92 info = import ./info.nix;
94 nixpkgs.overlays = overlays config.nixpkgs.hostPlatform.system;
95 #nixpkgs.buildPlatform = "x86_64-linux";
96 nixpkgs.config.allowUnfreePredicate =
98 builtins.elem (lib.getName pkg) [
104 inputs.nixpkgs.nixosModules.notDetected
105 inputs.home-manager.nixosModules.home-manager
107 home-manager.useGlobalPkgs = true;
108 home-manager.useUserPackages = true;
109 home-manager.verbose = true;
110 home-manager.backupFileExtension = null;
111 home-manager.extraSpecialArgs = {
112 inherit hostName inputs;
116 programs.ssh.knownHosts = {
120 "carotte.sourcephile.fr"
122 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKnnS0w9zm5KuWwlfJu+qEXC0asESQySPp76szyMTE3J";
127 "mermet.sourcephile.fr"
129 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFvKN2sIpH782MFjaOpcty1Hs/T/TPNJpXI08H3O3oxl";
134 "losurdo.sourcephile.fr"
136 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJkAq1T0Dxozt4RPylvWrUmeuejiG+n/owb3ucnWP9F";
144 # nix -L develop or direnv allow
145 devShell = forAllSystems (
146 { pkgs, system, ... }:
147 pkgs.callPackage ./shell.nix {
154 inherit (inputs.self.checks.${system}.git-hooks-check) shellHook;
158 # nix -L run .#mermet.switch
159 apps = forAllSystems (
160 { pkgs, system, ... }:
164 { config, pkgs, ... }:
166 inherit (config.system) build;
167 scriptApp = scriptName: ps: script: {
170 (pkgs.writeShellScript "${hostName}-${scriptName}" ''
171 export PATH="${lib.makeBinPath ([ pkgs.buildPackages.coreutils ] ++ ps)}:$PATH"
178 # Example: nix run .#mermet.switch
179 "switch" = scriptApp "switch" [ ] (''
183 chmod -R g-rwx,o-rwx **/*.gpg
184 trap 'git reset **/*.gpg' EXIT
185 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
187 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
188 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
190 nix copy --to ssh://${config.install.target}${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
192 ${config.security.initrd.install}
194 if ssh ${config.install.target} set -x ';' \
195 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
196 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
197 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
207 ${profile}/bin/switch-to-configuration switch
210 ${build.toplevel}/bin/switch-to-configuration test
212 ssh ${config.install.target} -o ControlPath=none set -x ';' \
213 systemctl stop nixos-fallback.service ';' \
214 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
215 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
216 nix-env --delete-generations 7d --profile ${profile}
219 echo WARNING: switch-to-configuration was not registered at boot
221 ssh ${config.install.target} -o ControlPath=none set -x ';' \
222 systemctl stop nixos-fallback.service
226 # Example: nix run .#carotte.install-sd
227 # DELETEME: quite useless, better to use nixos-install
228 "install-sd" = scriptApp "install-sd" [ pkgs.zstd ] ''
230 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.sdImage}
231 unzstd --stdout ${build.sdImage}/sd-image/*.img.zst |
232 sudo -k dd conv=notrunc oflag=direct,sync status=progress of="''${1:-/dev/mmcblk0}"
235 ) inputs.self.nixosConfigurations
239 checks = forAllSystems (
241 git-hooks-check = inputs.git-hooks.lib.${system}.run {
244 nixfmt-rfc-style.enable = true;