{ config, inputs, lib, pkgs, this, ... }: with lib; let cfg = config.nixfiles.modules.common.nix; in { imports = with inputs.srvos.nixosModules; [ mixins-nix-experimental mixins-trusted-nix-caches ]; options.nixfiles.modules.common.nix.allowedUnfreePackages = mkOption { description = "A list of allowed unfree packages."; type = with types; listOf str; default = [ ]; }; config = { _module.args = { pkgsLocal = packages.useNixpkgs "${config.my.home}/src/nixpkgs"; # Impure! }; 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 --no-eval-cache"; }; nix = let notSelfInputs = filterAttrs (n: _: n != "self") inputs; in { package = mkForce pkgs.nix; # Only use stable Nix. nixPath = mapAttrsToList (n: v: "${n}=${v}") notSelfInputs ++ [ "nixfiles=${config.my.home}/src/nixfiles" ]; registry = mapAttrs (_: flake: { inherit flake; }) notSelfInputs // { nixfiles.flake = inputs.self; }; settings = { warn-dirty = false; keep-going = true; experimental-features = [ "fetch-tree" "pipe-operators" ]; trusted-users = [ my.username ]; substituters = [ "https://cache.garnix.io" "https://cache.tvl.su" "https://nix-community.cachix.org" "https://numtide.cachix.org" ]; trusted-public-keys = [ "cache.tvl.su:kjc6KOMupXc1vHVufJUoDUYeLzbwSr9abcAKdn/U1Jk=" ]; # https://github.com/NixOS/nix/issues/6901 fallback = true; }; }; nixpkgs = { config.allowUnfreePredicate = p: elem (getName p) cfg.allowedUnfreePackages; overlays = [ inputs.self.overlays.default ]; }; programs.nh.enable = this.isHeadful; environment = { defaultPackages = [ ]; systemPackages = with pkgs; optionals this.isHeadful [ nix-tree nixfiles ]; variables = { NIXFILES = optionalString this.isHeadful "${config.my.home}/src/nixfiles"; NIX_SHELL_PRESERVE_PROMPT = "1"; }; }; system.stateVersion = this.stateVersion or trivial.release; }; }