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 nix-formatter-pack.follows = "julm-nix/nix-formatter-pack";
8 #nixpkgs.follows = "julm-nix/nixpkgs";
9 nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
10 git-hooks.follows = "julm-nix/git-hooks";
16 remoteNixpkgsPatches = import (inputs.julm-nix + "/nixpkgs/patches.nix");
17 localNixpkgsPatches = [
18 #nixpkgs/patches/systemd-coredump.diff
20 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
21 nixpkgsPath = originPkgs.applyPatches {
22 name = "nixpkgs-patched";
24 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
26 patch=$(printf '%s\n' ${
27 builtins.concatStringsSep " " (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)
29 sort | sha256sum | cut -c -7)
30 echo "-patch-$patch" >.version-suffix
33 profile = "/nix/var/nix/profiles/system";
34 inherit (inputs.nixpkgs) lib;
38 (finalPkgs: previousPkgs: { })
40 ++ import (inputs.julm-nix + "/nixpkgs/overlays.nix")
41 ++ import nixpkgs/overlays.nix;
42 #nixosSystem = lib.nixosSystem;
43 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
46 lib.genAttrs lib.systems.flakeExposed (
50 #pkgs = inputs.nixpkgs.legacyPackages.${system};
51 pkgs = import nixpkgsPath {
53 overlays = overlays system;
59 # nix -L build .#hello
60 packages = forAllSystems (args: with args; pkgs);
62 # nix -L build .#nixosConfigurations.mermet.config.system.build.toplevel
63 # nix -L build .#nixosConfigurations.mermet.config.boot.kernelPackages.kernel.configfile
64 # nix -L build .#nixosConfigurations.mermet.pkgs.hello
65 # nix eval --raw .#nixosConfigurations.mermet.config.networking.nftables.ruleset
69 lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (inputs.self + "/hosts"))
76 # Required to avoid infinite recursion
77 # when `inputs` is used in `imports`.
82 (inputs.julm-nix + "/nixos/default.nix")
83 (inputs.self + "/hosts/${hostName}.nix")
89 hosts = inputs.self.nixosConfigurations;
90 host = inputs.self.nixosConfigurations.${hostName}._module.args;
91 info = import ./info.nix;
93 nixpkgs.overlays = overlays config.nixpkgs.hostPlatform.system;
94 #nixpkgs.buildPlatform = "x86_64-linux";
95 nixpkgs.config.allowUnfreePredicate =
97 builtins.elem (lib.getName pkg) [
103 inputs.nixpkgs.nixosModules.notDetected
104 inputs.home-manager.nixosModules.home-manager
106 home-manager.useGlobalPkgs = true;
107 home-manager.useUserPackages = true;
108 home-manager.verbose = true;
109 home-manager.backupFileExtension = null;
110 home-manager.extraSpecialArgs = {
111 inherit hostName inputs;
115 programs.ssh.knownHosts = {
119 "carotte.sourcephile.fr"
121 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKnnS0w9zm5KuWwlfJu+qEXC0asESQySPp76szyMTE3J";
126 "mermet.sourcephile.fr"
128 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFvKN2sIpH782MFjaOpcty1Hs/T/TPNJpXI08H3O3oxl";
133 "losurdo.sourcephile.fr"
135 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJkAq1T0Dxozt4RPylvWrUmeuejiG+n/owb3ucnWP9F";
143 # nix -L develop or direnv allow
144 devShell = forAllSystems (
145 { pkgs, system, ... }:
146 pkgs.callPackage ./shell.nix {
153 inherit (inputs.self.checks.${system}.git-hooks-check) shellHook;
157 # nix -L run .#mermet.switch
158 apps = forAllSystems (
159 { pkgs, system, ... }:
163 { config, pkgs, ... }:
165 inherit (config.system) build;
166 scriptApp = scriptName: ps: script: {
169 (pkgs.writeShellScript "${hostName}-${scriptName}" ''
170 export PATH="${lib.makeBinPath ([ pkgs.buildPackages.coreutils ] ++ ps)}:$PATH"
177 # Example: nix run .#mermet.switch
178 "switch" = scriptApp "switch" [ ] (''
182 chmod -R g-rwx,o-rwx **/*.gpg
183 trap 'git reset **/*.gpg' EXIT
184 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
186 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
187 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
189 nix copy --to ssh://${config.install.target}${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
191 ${config.security.initrd.install}
193 if ssh ${config.install.target} set -x ';' \
194 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
195 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
196 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
206 ${profile}/bin/switch-to-configuration switch
209 ${build.toplevel}/bin/switch-to-configuration test
211 ssh ${config.install.target} -o ControlPath=none set -x ';' \
212 systemctl stop nixos-fallback.service ';' \
213 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
214 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
215 nix-env --delete-generations 7d --profile ${profile}
218 echo WARNING: switch-to-configuration was not registered at boot
220 ssh ${config.install.target} -o ControlPath=none set -x ';' \
221 systemctl stop nixos-fallback.service
225 # Example: nix run .#carotte.install-sd
226 # DELETEME: quite useless, better to use nixos-install
227 "install-sd" = scriptApp "install-sd" [ pkgs.zstd ] ''
229 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.sdImage}
230 unzstd --stdout ${build.sdImage}/sd-image/*.img.zst |
231 sudo -k dd conv=notrunc oflag=direct,sync status=progress of="''${1:-/dev/mmcblk0}"
234 ) inputs.self.nixosConfigurations
238 checks = forAllSystems (
240 git-hooks-check = inputs.git-hooks.lib.${system}.run {
243 nixfmt-rfc-style.enable = true;
250 formatter = forAllSystems (
252 inputs.nix-formatter-pack.lib.mkFormatter {
256 deadnix.enable = true;
257 nixfmt-rfc-style.enable = true;
258 statix.enable = true;