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.05";
10 git-hooks.follows = "julm-nix/git-hooks";
11 radicle-explorer.url = "git+https://seed.radicle.garden/z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git?rev=fb32e01a2fa84d104c114becf1a6a65636240305";
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' ${builtins.concatStringsSep " "
27 (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;
36 (finalPkgs: previousPkgs:
37 inputs.radicle-explorer.packages.${system}
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");
44 forAllSystems = f: lib.genAttrs lib.systems.flakeExposed (system: f rec {
46 #pkgs = inputs.nixpkgs.legacyPackages.${system};
47 pkgs = import nixpkgsPath { inherit system; overlays = overlays system; };
51 # nix -L build .#hello
52 packages = forAllSystems (args: with args; pkgs);
54 # nix -L build .#nixosConfigurations.mermet.config.system.build.toplevel
55 # nix -L build .#nixosConfigurations.mermet.config.boot.kernelPackages.kernel.configfile
56 # nix -L build .#nixosConfigurations.mermet.pkgs.hello
57 # nix eval --raw .#nixosConfigurations.mermet.config.networking.nftables.ruleset
58 nixosConfigurations = lib.genAttrs
59 (builtins.attrNames (lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (inputs.self + "/hosts"))))
60 (hostName: nixosSystem
64 # Required to avoid infinite recursion
65 # when `inputs` is used in `imports`.
70 (inputs.julm-nix + "/nixos/default.nix")
71 (inputs.self + "/hosts/${hostName}.nix")
75 hosts = inputs.self.nixosConfigurations;
76 host = inputs.self.nixosConfigurations.${hostName}._module.args;
77 info = import ./info.nix;
79 nixpkgs.overlays = overlays config.nixpkgs.hostPlatform.system;
80 #nixpkgs.buildPlatform = "x86_64-linux";
81 nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ "hplip" ];
83 inputs.nixpkgs.nixosModules.notDetected
84 inputs.home-manager.nixosModules.home-manager
86 home-manager.useGlobalPkgs = true;
87 home-manager.useUserPackages = true;
88 home-manager.verbose = true;
89 home-manager.backupFileExtension = null;
90 home-manager.extraSpecialArgs = {
91 inherit hostName inputs;
95 programs.ssh.knownHosts = {
97 extraHostNames = [ "carotte" "carotte.sourcephile.fr" ];
98 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKnnS0w9zm5KuWwlfJu+qEXC0asESQySPp76szyMTE3J";
101 extraHostNames = [ "mermet" "mermet.sourcephile.fr" ];
102 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFvKN2sIpH782MFjaOpcty1Hs/T/TPNJpXI08H3O3oxl";
105 extraHostNames = [ "losurdo" "losurdo.sourcephile.fr" ];
106 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJkAq1T0Dxozt4RPylvWrUmeuejiG+n/owb3ucnWP9F";
114 # nix -L develop or direnv allow
115 devShell = forAllSystems ({ pkgs, system, ... }: pkgs.callPackage ./shell.nix
117 inherit pkgs inputs system nixpkgsPath;
118 inherit (inputs.self.checks.${system}.git-hooks-check) shellHook;
121 # nix -L run .#mermet.switch
122 apps = forAllSystems ({ pkgs, system, ... }:
125 (hostName: { config, pkgs, ... }:
127 inherit (config.system) build;
128 scriptApp = scriptName: ps: script: {
130 program = (pkgs.writeShellScript "${hostName}-${scriptName}" ''
131 export PATH="${lib.makeBinPath ([ pkgs.buildPackages.coreutils ] ++ ps)}:$PATH"
138 # Example: nix run .#mermet.switch
139 "switch" = scriptApp "switch" [ ] (
144 chmod -R g-rwx,o-rwx **/*.gpg
145 trap 'git reset **/*.gpg' EXIT
146 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
148 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
149 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
151 nix copy --to ssh://${config.install.target}${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
153 ${config.security.initrd.install}
155 if ssh ${config.install.target} set -x ';' \
156 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
157 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
158 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
159 PATH=${with pkgs; lib.makeBinPath [ coreutils nix systemd ]}
161 ${profile}/bin/switch-to-configuration switch
164 ${build.toplevel}/bin/switch-to-configuration test
166 ssh ${config.install.target} -o ControlPath=none set -x ';' \
167 systemctl stop nixos-fallback.service ';' \
168 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
169 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
170 nix-env --delete-generations 7d --profile ${profile}
173 echo WARNING: switch-to-configuration was not registered at boot
175 ssh ${config.install.target} -o ControlPath=none set -x ';' \
176 systemctl stop nixos-fallback.service
181 # Example: nix run .#carotte.install-sd
182 # DELETEME: quite useless, better to use nixos-install
183 "install-sd" = scriptApp "install-sd" [ pkgs.zstd ] ''
185 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.sdImage}
186 unzstd --stdout ${build.sdImage}/sd-image/*.img.zst |
187 sudo -k dd conv=notrunc oflag=direct,sync status=progress of="''${1:-/dev/mmcblk0}"
191 inputs.self.nixosConfigurations
195 checks = forAllSystems (args: with args; {
196 git-hooks-check = inputs.git-hooks.lib.${system}.run {
199 nixpkgs-fmt.enable = true;
205 formatter = forAllSystems ({ pkgs, ... }:
206 inputs.nix-formatter-pack.lib.mkFormatter {
210 deadnix.enable = true;
211 nixpkgs-fmt.enable = true;
212 statix.enable = true;