3 #doom-emacs.follows = "julm-nix/doom-emacs";
4 home-manager.follows = "julm-nix/home-manager";
5 #julm-nix.inputs.nixpkgs.follows = "nixpkgs";
6 julm-nix.url = "git+file:///home/julm/work/sourcephile/nix/julm-nix?ref=main";
7 nixpkgs.follows = "julm-nix/nixpkgs";
8 #nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
9 git-hooks.follows = "julm-nix/git-hooks";
15 remoteNixpkgsPatches = import (inputs.julm-nix + "/nixpkgs/patches.nix");
16 localNixpkgsPatches = [
17 #nixpkgs/patches/systemd-coredump.diff
19 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
20 nixpkgsPath = originPkgs.applyPatches {
21 name = "nixpkgs-patched";
23 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
25 patch=$(printf '%s\n' ${
26 builtins.concatStringsSep " " (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)
28 sort | sha256sum | cut -c -7)
29 echo "-patch-$patch" >.version-suffix
32 profile = "/nix/var/nix/profiles/system";
33 inherit (inputs.nixpkgs) lib;
37 (finalPkgs: previousPkgs: { })
39 ++ import (inputs.julm-nix + "/nixpkgs/overlays.nix") args
40 ++ import nixpkgs/overlays.nix args;
41 #nixosSystem = lib.nixosSystem;
42 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
45 lib.genAttrs lib.systems.flakeExposed (
49 #pkgs = inputs.nixpkgs.legacyPackages.${system};
50 pkgs = import nixpkgsPath {
52 overlays = overlays { inherit inputs system; };
58 # nix -L build .#hello
59 packages = forAllSystems (args: with args; pkgs);
61 # nix -L build .#nixosConfigurations.mermet.config.system.build.toplevel
62 # nix -L build .#nixosConfigurations.mermet.config.boot.kernelPackages.kernel.configfile
63 # nix -L build .#nixosConfigurations.mermet.pkgs.hello
64 # nix eval --raw .#nixosConfigurations.mermet.config.networking.nftables.ruleset
68 lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (inputs.self + "/hosts"))
75 # Required to avoid infinite recursion
76 # when `inputs` is used in `imports`.
81 (inputs.julm-nix + "/nixos/default.nix")
82 (inputs.self + "/hosts/${hostName}.nix")
88 hosts = inputs.self.nixosConfigurations;
89 host = inputs.self.nixosConfigurations.${hostName}._module.args;
90 info = import ./info.nix;
92 nixpkgs.overlays = overlays {
94 inherit (config.nixpkgs.hostPlatform) system;
96 #nixpkgs.buildPlatform = "x86_64-linux";
97 nixpkgs.config.allowUnfreePredicate =
99 builtins.elem (lib.getName pkg) [
105 inputs.nixpkgs.nixosModules.notDetected
106 inputs.home-manager.nixosModules.home-manager
108 home-manager.useGlobalPkgs = true;
109 home-manager.useUserPackages = true;
110 home-manager.verbose = true;
111 home-manager.backupFileExtension = null;
112 home-manager.extraSpecialArgs = {
113 inherit hostName inputs;
117 programs.ssh.knownHosts = {
121 "carotte.sourcephile.fr"
123 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKnnS0w9zm5KuWwlfJu+qEXC0asESQySPp76szyMTE3J";
128 "mermet.sourcephile.fr"
130 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFvKN2sIpH782MFjaOpcty1Hs/T/TPNJpXI08H3O3oxl";
135 "losurdo.sourcephile.fr"
137 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJkAq1T0Dxozt4RPylvWrUmeuejiG+n/owb3ucnWP9F";
145 # nix -L develop or direnv allow
146 devShell = forAllSystems (
147 { pkgs, system, ... }:
148 pkgs.callPackage ./shell.nix {
155 inherit (inputs.self.checks.${system}.git-hooks-check) shellHook;
159 # nix -L run .#mermet.switch
160 apps = forAllSystems (
161 { pkgs, system, ... }:
165 { config, pkgs, ... }:
167 inherit (config.system) build;
168 scriptApp = scriptName: ps: script: {
171 (pkgs.writeShellScript "${hostName}-${scriptName}" ''
172 export PATH="${lib.makeBinPath ([ pkgs.buildPackages.coreutils ] ++ ps)}:$PATH"
179 # Example: nix run .#mermet.switch
180 "switch" = scriptApp "switch" [ ] (''
184 chmod -R g-rwx,o-rwx **/*.gpg
185 trap 'git reset **/*.gpg' EXIT
186 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
188 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
189 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
191 nix copy --to ssh://${config.install.target}${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
193 ${config.security.initrd.install}
195 if ssh ${config.install.target} set -x ';' \
196 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
197 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
198 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
208 ${profile}/bin/switch-to-configuration switch
211 ${build.toplevel}/bin/switch-to-configuration test
213 ssh ${config.install.target} -o ControlPath=none set -x ';' \
214 systemctl stop nixos-fallback.service ';' \
215 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
216 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
217 nix-env --delete-generations 7d --profile ${profile}
220 echo WARNING: switch-to-configuration was not registered at boot
222 ssh ${config.install.target} -o ControlPath=none set -x ';' \
223 systemctl stop nixos-fallback.service
227 # Example: nix run .#carotte.install-sd
228 # DELETEME: quite useless, better to use nixos-install
229 "install-sd" = scriptApp "install-sd" [ pkgs.zstd ] ''
231 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.sdImage}
232 unzstd --stdout ${build.sdImage}/sd-image/*.img.zst |
233 sudo -k dd conv=notrunc oflag=direct,sync status=progress of="''${1:-/dev/mmcblk0}"
236 ) inputs.self.nixosConfigurations
240 checks = forAllSystems (
242 git-hooks-check = inputs.git-hooks.lib.${system}.run {
245 nixfmt-rfc-style.enable = true;