{ config, inputs, lib, localUsername ? lib.my.username, pkgs, this, ... }: with lib; { _module.args = let importNixpkgs = nixpkgs: import nixpkgs { inherit (config.nixpkgs) config; inherit (this) system; }; in rec { pkgsLocal = importNixpkgs "${config.my.home}/src/nixpkgs"; # Impure! pkgsMaster = importNixpkgs inputs.nixpkgs-master; pkgsStable = importNixpkgs inputs.nixpkgs-stable; pkgsRev = rev: hash: importNixpkgs (pkgs.fetchFromGitHub { owner = "NixOS"; repo = "nixpkgs"; inherit rev hash; }); pkgsPr = pr: pkgsRev "refs/pull/${toString pr}/head"; }; nix = let notSelfInputs = filterAttrs (n: _: n != "self") inputs; in { settings = { # https://nixos.org/manual/nix/unstable/contributing/experimental-features.html#currently-available-experimental-features # https://github.com/NixOS/nix/blob/master/src/libutil/experimental-features.cc experimental-features = concatStringsSep " " [ "flakes" "nix-command" "recursive-nix" "repl-flake" ]; keep-derivations = if this.isHeadful then "true" else "false"; keep-outputs = if this.isHeadful then "true" else "false"; flake-registry = "${inputs.flake-registry}/flake-registry.json"; warn-dirty = false; substituters = [ "https://azahi.cachix.org" "https://cache.iog.io" "https://cachix.cachix.org" "https://nix-community.cachix.org" "https://pre-commit-hooks.cachix.org" ]; trusted-public-keys = [ "azahi.cachix.org-1:2bayb+iWYMAVw3ZdEpVg+NPOHCXncw7WMQ0ElX1GO3s=" "cachix.cachix.org-1:eWNHQldwUO7G2VkjpnjDbWwy4KQ/HNxht7H4SSoMckM=" "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" "pre-commit-hooks.cachix.org-1:Pkk3Panw5AW24TOv6kz3PvLhlH8puAsJTBbOPmBo7Rc=" ]; trusted-users = ["root" localUsername]; }; nixPath = mapAttrsToList (n: v: "${n}=${v}") notSelfInputs ++ ["nixfiles=${config.my.home}/src/nixfiles"]; registry = mapAttrs (_: flake: {inherit flake;}) notSelfInputs // {nixfiles.flake = inputs.self;}; }; nixpkgs.overlays = with inputs; [ self.overlays.default nur.overlay (_: _: { }) ]; environment = { systemPackages = with pkgs; optionals this.isHeadful [ nix-top nix-tree nixfiles ]; variables.NIXFILES = "${config.my.home}/src/nixfiles"; }; hm = { # Used primarily in conjunction with the "nixfiles" script. home.file.".nix-defexpr/default.nix".text = let hostname = strings.escapeNixIdentifier this.hostname; in optionalString this.isHeadful '' let self = builtins.getFlake "nixfiles"; configurations = self.nixosConfigurations; local = configurations.${hostname}; in rec { inherit self; inherit (self) inputs lib; inherit (lib) my; this = my.configurations.${hostname}; inherit (local) config; inherit (local.config.system.build) toplevel vm vmWithBootLoader manual; pretty = expr: lib.trace (lib.generators.toPretty {} expr) {}; } // configurations // local._module.args ''; programs.bash.shellAliases.nix = "nix --verbose --print-build-logs"; }; }