{ inputs = { doom-emacs.follows = "julm-nix/doom-emacs"; home-manager.follows = "julm-nix/home-manager"; julm-nix.url = "git+file:///home/julm/work/sourcephile/nix/julm-nix?ref=main"; julm-nix.inputs.nixpkgs.follows = "nixpkgs"; nix-formatter-pack.follows = "julm-nix/nix-formatter-pack"; nixpkgs.url = "github:NixOS/nixpkgs/fdebb81f45a1ba2c4afca5fd9f526e1653ad0949"; pre-commit-hooks.follows = "julm-nix/pre-commit-hooks"; }; outputs = inputs: let remoteNixpkgsPatches = import (inputs.julm-nix + "/nixpkgs/patches.nix"); localNixpkgsPatches = [ #nixpkgs/patches/systemd-coredump.diff ]; originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux"; nixpkgsPath = originPkgs.applyPatches { name = "nixpkgs-patched"; src = inputs.nixpkgs; patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches; postPatch = '' patch=$(printf '%s\n' ${builtins.concatStringsSep " " (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} | sort | sha256sum | cut -c -7) echo "+patch-$patch" >.version-suffix ''; }; lib = inputs.nixpkgs.lib; #nixosSystem = lib.nixosSystem; nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix"); pkgsForSystem = system: import nixpkgsPath { inherit system; config = { allowUnfree = true; # For hplip }; overlays = import nixpkgs/overlays.nix ++ import (inputs.julm-nix + "/nixpkgs/overlays.nix"); }; forAllSystems = f: lib.genAttrs lib.systems.flakeExposed (system: f rec { inherit system; #pkgs = inputs.nixpkgs.legacyPackages.${system}; pkgs = pkgsForSystem system; }); in { # Example: nix -L build .#nixosConfigurations.losurdo.config.system.build.toplevel # Example: nix -L build .#nixosConfigurations.losurdo.config.boot.kernelPackages.kernel.configfile # Example: nix -L build .#nixosConfigurations.losurdo.pkgs.hello # Example: nix eval .#nixosConfigurations.losurdo.config.networking.hostName nixosConfigurations = lib.genAttrs (builtins.attrNames (lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (inputs.self + "/hosts")))) (hostName: nixosSystem { system = null; specialArgs = { # Required to avoid infinite recrsion # when inputs is used in imports inherit inputs; }; modules = [ (inputs.self + "/hosts/${hostName}.nix") { _module.args = { inherit hostName; hosts = inputs.self.nixosConfigurations; host = inputs.self.nixosConfigurations.${hostName}._module.args; #pkgs = pkgsForSystem "x86_64-linux"; #pkgs = pkgsForSystem config._module.args.system; }; nixpkgs.overlays = import nixpkgs/overlays.nix ++ import (inputs.julm-nix + "/nixpkgs/overlays.nix"); #nixpkgs.buildPlatform = "x86_64-linux"; } nixos/defaults.nix inputs.nixpkgs.nixosModules.notDetected ({ pkgs, ... }: { nix.registry.nixpkgs = lib.mkDefault { flake = inputs.nixpkgs; }; nix.package = pkgs.nixFlakes; nix.extraOptions = "experimental-features = nix-command flakes"; #nixpkgs.overlays = import nixpkgs/overlays.nix; # Let 'nixos-version --json' know about the Git revision of this flake. system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev; }) inputs.home-manager.nixosModules.home-manager { home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; home-manager.verbose = true; home-manager.backupFileExtension = null; home-manager.extraSpecialArgs = { inherit hostName inputs; }; } { programs.ssh.knownHosts = { carotte = { extraHostNames = [ "carotte" "carotte.sourcephile.fr" ]; publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKnnS0w9zm5KuWwlfJu+qEXC0asESQySPp76szyMTE3J"; }; mermet = { extraHostNames = [ "mermet" "mermet.sourcephile.fr" ]; publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFvKN2sIpH782MFjaOpcty1Hs/T/TPNJpXI08H3O3oxl"; }; losurdo = { extraHostNames = [ "losurdo" "losurdo.sourcephile.fr" ]; publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJkAq1T0Dxozt4RPylvWrUmeuejiG+n/owb3ucnWP9F"; }; }; } ]; } ); #legacyPackages = pkgsForSystem "x86_64-linux"; # nix -L develop or direnv allow devShell = forAllSystems ({ pkgs, system, ... }: pkgs.callPackage ./shell.nix { inherit pkgs inputs system nixpkgsPath; #inherit (inputs.self.checks.${system}.pre-commit-check) shellHook; }); # nix -L run .#oignon.switch apps = forAllSystems ({ pkgs, system, ... }: with builtins; mapAttrs (hostName: { config, ... }: let inherit (config.system) build; target = "\"\${TARGET:-root@${config.networking.hostName}.${config.networking.domain}}\""; scriptApp = scriptName: ps: script: { type = "app"; program = (pkgs.writeShellScript "${hostName}-${scriptName}" '' export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH" set -eux ${script} '').outPath; }; in { # Example: nix run .#aubergine.switch "switch" = scriptApp "switch" [ ] '' shopt -s globstar chmod -R g-rwx,o-rwx **/*.gpg trap 'git reset **/*.gpg' EXIT git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath} nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel} nix copy --to ssh://${target}${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel} '' + lib.optionalString config.boot.initrd.network.ssh.enable '' # Send the SSH key of the initrd gpg --decrypt 'pass/hosts/${hostName}/initrd/ssh.key.gpg' | ssh ${target} install -D -m 400 -o root -g root /dev/stdin /root/initrd/ssh.key # Send the Wireguard key of the initrd gpg --decrypt 'pass/hosts/${hostName}/wireguard/wg-intra/privateKey.gpg' | ssh ${target} install -D -m 400 -o root -g root /dev/stdin /root/initrd/wg-intra.key '' + '' ssh ${target} set -x ';' \ systemctl reset-failed nixos-fallback '2>/dev/null' ';' \ systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\''' PATH=${with pkgs; lib.makeBinPath [ coreutils nix systemd ]} sleep $((10 * 60)) ${profile}/bin/switch-to-configuration switch systemctl reboot '\'''' '&&' \ ${build.toplevel}/bin/switch-to-configuration test ssh ${target} -o ControlPath=none set -x ';' \ systemctl stop nixos-fallback.service ';' \ nix-env --profile ${profile} --set '${build.toplevel}' ';' \ ${build.toplevel}/bin/switch-to-configuration boot '&&' \ nix-env --delete-generations 7d --profile ${profile} ''; # Example: nix run .#carotte.install-sd # DELETEME: quite useless, better to use nixos-install "install-sd" = scriptApp "install-sd" [ zstd ] '' set -o pipefail nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.sdImage} unzstd --stdout ${build.sdImage}/sd-image/*.img.zst | sudo -k dd conv=notrunc oflag=direct,sync status=progress of="''${1:-/dev/mmcblk0}" ''; } ) inputs.self.nixosConfigurations ); }; }