2 inputs.nixpkgs.url = "github:NixOS/nixpkgs/32096899af23d49010bd8cf6a91695888d9d9e73";
3 inputs.home-manager.url = "github:nix-community/home-manager";
4 inputs.home-manager.inputs.nixpkgs.follows = "nixpkgs";
5 inputs.doom-emacs.url = "github:hlissner/doom-emacs";
6 inputs.doom-emacs.flake = false;
8 inputs.nix-doom-emacs.url = "github:vlaci/nix-doom-emacs";
9 inputs.nix-doom-emacs.inputs.nixpkgs.follows = "nixpkgs";
10 inputs.nix-doom-emacs.inputs.home-manager.follows = "home-manager";
11 inputs.nix-doom-emacs.inputs.flake-utils.follows = "flake-utils";
12 inputs.nix-doom-emacs.inputs.emacs-overlay.follows = "emacs-overlay";
13 inputs.emacs-overlay.url = "github:nix-community/emacs-overlay/master";
15 #inputs.pass = { type = "path"; path = "./pass"; flake = false; };
18 remoteNixpkgsPatches = import nixpkgs/patches.nix;
19 localNixpkgsPatches = [
21 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
22 nixpkgsPath = originPkgs.applyPatches {
23 name = "nixpkgs-patched";
24 src = inputs.nixpkgs.outPath;
25 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
27 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
28 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
29 sort | sha256sum | cut -c -7)
30 echo "-patch-$patch" >.version-suffix
33 lib = inputs.nixpkgs.lib;
34 profile = "/nix/var/nix/profiles/system";
35 forAllSystems = f: lib.genAttrs lib.systems.flakeExposed (system: f rec {
37 #pkgs = inputs.nixpkgs.legacyPackages.${system};
38 pkgs = pkgsForSystem system;
40 pkgsForSystem = system: import nixpkgsPath {
43 allowUnfree = true; # For hplip
45 overlays = import nixpkgs/overlays.nix;
47 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
48 #nixosSystem = inputs.nixpkgs.lib.nixosSystem;
50 nixosConfigurations = lib.genAttrs
51 (builtins.attrNames (lib.filterAttrs (n: v: v == "directory") (builtins.readDir ./hosts)))
52 (hostName: nixosSystem {
53 system = "x86_64-linux";
54 pkgs = pkgsForSystem "x86_64-linux";
56 inherit hostName inputs;
60 config._module.args = {
61 inherit hostName inputs;
62 hosts = inputs.self.nixosConfigurations;
65 (import nixos/modules.nix)
66 (import nixos/options.nix)
67 (import (./hosts + "/${hostName}.nix"))
68 inputs.nixpkgs.nixosModules.notDetected
69 inputs.home-manager.nixosModules.home-manager
71 nix.registry.nixpkgs = lib.mkDefault { flake = inputs.nixpkgs; };
72 nix.package = pkgs.nixFlakes;
73 nix.extraOptions = "experimental-features = nix-command flakes";
74 #nixpkgs.overlays = import nixpkgs/overlays.nix;
76 system.nixos.versionSuffix = ".${
77 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
78 inputs.self.shortRev or "dirty"}";
79 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
81 # Let 'nixos-version --json' know about the Git revision of this flake.
82 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
84 system.configurationRevision =
87 else throw "Refusing to build from a dirty Git tree!";
91 home-manager.useGlobalPkgs = true;
92 home-manager.useUserPackages = true;
93 home-manager.verbose = true;
94 home-manager.backupFileExtension = null;
95 home-manager.extraSpecialArgs = {
96 inherit hostName inputs;
101 # nix -L develop or direnv allow
102 devShell = forAllSystems ({ pkgs, system, ... }: pkgs.callPackage ./shell.nix
104 inherit pkgs inputs system nixpkgsPath;
105 #inherit (checks.${system}.pre-commit-check) shellHook;
107 # nix -L run .#oignon.switch
108 apps = forAllSystems ({ pkgs, system, ... }:
110 mapAttrs (hostName: { config, ... }:
112 build = config.system.build;
113 target = "\"\${TARGET:-root@${config.networking.hostName}.${config.networking.domain}}\"";
114 scriptApp = scriptName: ps: script: {
116 program = (pkgs.writeShellScript "${hostName}-${scriptName}" ''
117 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
123 # Example: nix run .#aubergine.switch
124 "switch" = scriptApp "switch" [] ''
127 chmod -R g-rwx,o-rwx **/*.gpg
128 trap 'git reset **/*.gpg' EXIT
129 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
131 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
132 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
134 nix copy --to ssh://${target}${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
136 ssh ${target} set -x ';' \
137 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
138 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
139 PATH=${with pkgs; lib.makeBinPath [ coreutils nix systemd ]}
140 fallback=$(realpath -e ${profile})
142 nix-env --profile ${profile} --set $fallback
143 $fallback/bin/switch-to-configuration switch
146 ${profile}/bin/switch-to-configuration test
148 ssh ${target} -o ControlPath=none set -x ';' \
149 systemctl stop nixos-fallback.service ';' \
150 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
151 ${profile}/bin/switch-to-configuration boot '&&' \
152 nix-env --delete-generations 7d --profile ${profile}
154 }) inputs.self.nixosConfigurations);