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")
40 ++ import nixpkgs/overlays.nix;
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 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 config.nixpkgs.hostPlatform.system;
93 #nixpkgs.buildPlatform = "x86_64-linux";
94 nixpkgs.config.allowUnfreePredicate =
96 builtins.elem (lib.getName pkg) [
102 inputs.nixpkgs.nixosModules.notDetected
103 inputs.home-manager.nixosModules.home-manager
105 home-manager.useGlobalPkgs = true;
106 home-manager.useUserPackages = true;
107 home-manager.verbose = true;
108 home-manager.backupFileExtension = null;
109 home-manager.extraSpecialArgs = {
110 inherit hostName inputs;
114 programs.ssh.knownHosts = {
118 "carotte.sourcephile.fr"
120 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKnnS0w9zm5KuWwlfJu+qEXC0asESQySPp76szyMTE3J";
125 "mermet.sourcephile.fr"
127 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFvKN2sIpH782MFjaOpcty1Hs/T/TPNJpXI08H3O3oxl";
132 "losurdo.sourcephile.fr"
134 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJkAq1T0Dxozt4RPylvWrUmeuejiG+n/owb3ucnWP9F";
142 # nix -L develop or direnv allow
143 devShell = forAllSystems (
144 { pkgs, system, ... }:
145 pkgs.callPackage ./shell.nix {
152 inherit (inputs.self.checks.${system}.git-hooks-check) shellHook;
156 # nix -L run .#mermet.switch
157 apps = forAllSystems (
158 { pkgs, system, ... }:
162 { config, pkgs, ... }:
164 inherit (config.system) build;
165 scriptApp = scriptName: ps: script: {
168 (pkgs.writeShellScript "${hostName}-${scriptName}" ''
169 export PATH="${lib.makeBinPath ([ pkgs.buildPackages.coreutils ] ++ ps)}:$PATH"
176 # Example: nix run .#mermet.switch
177 "switch" = scriptApp "switch" [ ] (''
181 chmod -R g-rwx,o-rwx **/*.gpg
182 trap 'git reset **/*.gpg' EXIT
183 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
185 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
186 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
188 nix copy --to ssh://${config.install.target}${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
190 ${config.security.initrd.install}
192 if ssh ${config.install.target} set -x ';' \
193 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
194 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
195 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
205 ${profile}/bin/switch-to-configuration switch
208 ${build.toplevel}/bin/switch-to-configuration test
210 ssh ${config.install.target} -o ControlPath=none set -x ';' \
211 systemctl stop nixos-fallback.service ';' \
212 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
213 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
214 nix-env --delete-generations 7d --profile ${profile}
217 echo WARNING: switch-to-configuration was not registered at boot
219 ssh ${config.install.target} -o ControlPath=none set -x ';' \
220 systemctl stop nixos-fallback.service
224 # Example: nix run .#carotte.install-sd
225 # DELETEME: quite useless, better to use nixos-install
226 "install-sd" = scriptApp "install-sd" [ pkgs.zstd ] ''
228 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.sdImage}
229 unzstd --stdout ${build.sdImage}/sd-image/*.img.zst |
230 sudo -k dd conv=notrunc oflag=direct,sync status=progress of="''${1:-/dev/mmcblk0}"
233 ) inputs.self.nixosConfigurations
237 checks = forAllSystems (
239 git-hooks-check = inputs.git-hooks.lib.${system}.run {
242 nixfmt-rfc-style.enable = true;