2 inputs.nixpkgs.url = "github:NixOS/nixpkgs/495b19d5b3e62b4ec7e846bdfb6ef3d9c3b83492";
3 inputs.flake-utils.url = "github:numtide/flake-utils";
4 inputs.home-manager.url = "github:nix-community/home-manager";
5 inputs.home-manager.inputs.nixpkgs.follows = "nixpkgs";
6 inputs.doom-emacs.url = "github:hlissner/doom-emacs";
7 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";
14 #inputs.pass = { type = "path"; path = "./pass"; flake = false; };
17 remoteNixpkgsPatches = import nixpkgs/patches.nix;
18 localNixpkgsPatches = [
20 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
21 nixpkgsPath = originPkgs.applyPatches {
22 name = "nixpkgs-patched";
23 src = inputs.nixpkgs.outPath;
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
33 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
34 #nixosSystem = inputs.nixpkgs.lib.nixosSystem;
36 nixosConfigurations = lib.genAttrs
37 (builtins.attrNames (lib.filterAttrs (n: v: v == "directory") (builtins.readDir ./hosts)))
38 (hostName: nixosSystem rec {
39 system = "x86_64-linux";
41 inherit hostName inputs;
42 # Encrypted using git-crypt, hence kept out of /nix/store
43 private = "/root/private";
44 # Encrypted using systemd-creds, hence can go into the /nix/store
45 credentials = private/hosts + "/${hostName}/credentials";
47 pkgs = import nixpkgsPath {
49 config.allowUnfree = true; # For hplip
50 overlays = import nixpkgs/overlays.nix;
54 config._module.args = {
55 inherit hostName inputs;
56 hosts = inputs.self.nixosConfigurations;
59 (import nixos/options.nix)
60 (import (./hosts + "/${hostName}.nix"))
61 inputs.nixpkgs.nixosModules.notDetected
62 inputs.home-manager.nixosModules.home-manager
64 nix.registry.nixpkgs = lib.mkDefault { flake = inputs.nixpkgs; };
65 nix.package = pkgs.nixFlakes;
66 nix.extraOptions = "experimental-features = nix-command flakes";
67 #nixpkgs.overlays = import nixpkgs/overlays.nix;
69 system.nixos.versionSuffix = ".${
70 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
71 inputs.self.shortRev or "dirty"}";
72 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
74 # Let 'nixos-version --json' know about the Git revision of this flake.
75 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
77 system.configurationRevision =
80 else throw "Refusing to build from a dirty Git tree!";
84 home-manager.useGlobalPkgs = true;
85 home-manager.useUserPackages = true;
86 home-manager.verbose = true;
87 home-manager.backupFileExtension = null;
88 home-manager.extraSpecialArgs = {
89 inherit hostName inputs;
95 inputs.flake-utils.lib.eachDefaultSystem (system:
96 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
98 pkgs = import nixpkgsPath {
100 config = {}; # Make the config pure, ignoring user's config.
101 overlays = import nixpkgs/overlays.nix;
103 devShell = import ./shell.nix { inherit pkgs inputs system; };
104 apps = builtins.mapAttrs (hostName: { config, ... }: let
105 build = config.system.build;
106 target = "\"\${TARGET:-root@${config.networking.hostName}.${config.networking.domain}}\"";
107 profile = "/nix/var/nix/profiles/system";
109 # Example: nix run .#aubergine.switch
112 program = (pkgs.writeShellScript "switch" (''
116 chmod -R g-rwx,o-rwx "private/root"
117 trap 'git reset private/root private/hosts/*/root' EXIT
118 git rm -rf --cached --ignore-unmatch private/root private/hosts/*/root # prevent copying to /nix/store
120 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
121 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
122 nix copy --to ssh://${target}${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
124 nix-env --profile '${profile}' --set '${build.toplevel}' '&&' \
125 '${profile}'/bin/switch-to-configuration switch
129 }) inputs.self.nixosConfigurations;