diff --git a/data/eval-machines.nix b/data/eval-machines.nix index 4e32e6f..e41c793 100644 --- a/data/eval-machines.nix +++ b/data/eval-machines.nix @@ -3,10 +3,9 @@ let network = import networkExpr; - pkgs = network.network.pkgs; - lib = pkgs.lib; + netPkgs = network.network.pkgs; + lib = netPkgs.lib; in - with pkgs; with lib; rec { @@ -18,10 +17,30 @@ rec { # expression, attaching _file attributes so the NixOS module # system can give sensible error messages. modules = [ { imports = [ network.${machineName} ]; } { inherit (network) _file; } ]; + + customPath = lib.attrByPath [ "deployment" "nixPath" ] [] (network.${machineName} { config = {}; pkgs = {}; }); + + # add path of network.pkgs if customPath is empty + netPath = if customPath == [] then [ { prefix = "nixpkgs"; path = netPkgs.path; } ] else []; + + __nixPath = customPath ++ netPath ++ builtins.nixPath; + + # must stay before __nixPath so we resolve correctly + importTarget = lib.attrByPath [ "deployment" "importPath" ] (network.${machineName} { config = {}; pkgs = {}; }); + + importFn = + let + overrides = { + inherit __nixPath; + import = fn: scopedImport overrides fn; + scopedImport = attrs: fn: scopedImport (overrides // attrs) fn; + builtins = builtins // overrides; + }; + in + scopedImport overrides; in { name = machineName; - value = import "${toString pkgs.path}/nixos/lib/eval-config.nix" { - inherit pkgs; + value = importFn importTarget { modules = modules ++ [ { key = "deploy-stuff"; @@ -57,7 +76,7 @@ rec { flip mapAttrs nodes (n: v': let v = scrubOptionValue v'; in { inherit (v.config.deployment) targetHost secrets healthChecks buildOnly; name = n; - nixosRelease = v.config.system.nixos.release or (removeSuffix v.config.system.nixos.version.suffix v.config.system.nixos.version); + #nixosRelease = v.config.system.nixos.release or (removeSuffix v.config.system.nixos.version.suffix v.config.system.nixos.version); } ); @@ -68,7 +87,7 @@ rec { # Phase 2: build complete machine configurations. machines = { names, buildTargets ? null }: let nodes' = filterAttrs (n: v: elem n names) nodes; in - pkgs.runCommand "morph" + netPkgs.runCommand "morph" { preferLocalBuild = true; } (if buildTargets == null then '' diff --git a/data/options.nix b/data/options.nix index 4488c17..af87847 100644 --- a/data/options.nix +++ b/data/options.nix @@ -161,6 +161,25 @@ in type = str; }; + nixPath = mkOption { + type = attrsOf unspecified; + default = []; + example = [ { prefix = "nixpkgs"; path = "/home/test/git"; } ]; + dsecription = '' + Per machine NIX_PATH override(s) + ''; + + }; + + importPath = mkOption { + type = str; + dsecription = '' + Per machine import path of config evaluator (operating system entry point) + + By default this is + ''; + }; + buildOnly = mkOption { type = bool; default = false; diff --git a/examples/pinning.nix b/examples/pinning.nix new file mode 100644 index 0000000..3dab9ad --- /dev/null +++ b/examples/pinning.nix @@ -0,0 +1,74 @@ +let + # Pin the deployment package-set to a specific version of nixpkgs + oldPkgs = import (builtins.fetchTarball { + url = "https://github.com/NixOS/nixpkgs-channels/archive/98c1150f2cc62b94b693dce63adc1fbcbfe616f1.tar.gz"; + sha256 = "1mdwn0qrjc8jli8cbi4cfkar6xq15l232r371p4b48v2d4bah3wp"; + }) {}; + + #sysPkgs = import {}; + + newPkgs = import (builtins.fetchTarball { + url = "https://github.com/NixOS/nixpkgs-channels/archive/180aa21259b666c6b7850aee00c5871c89c0d939.tar.gz"; + sha256 = "0gxd10djy6khbjb012s9fl3lpjzqaknfv2g4dpfjxwwj9cbkj04h"; + }) {}; + + vpsfPkgs = builtins.fetchTarball { + url = "https://github.com/vpsfreecz/nixpkgs/archive/5dd15a4181fb260d1c006c4d00e4cc978cd89989.tar.gz"; + sha256 = "0yg9059n08469mndvpq1f5x3lcnj9zrynkckwh9pii1ihimj6xyl"; + }; + + vpsadminos = builtins.fetchTarball { + url = "https://github.com/vpsfreecz/vpsadminos/archive/c00b238f4d290c8eded24ca3d0ae97c320bded91.tar.gz"; + sha256 = "10m9sc49gz5j71xwm65pdw4wz683w37csi5zjfrs1jxdgy70j0pd"; + }; + +in +{ + network = { + pkgs = newPkgs; + description = "simple hosts"; + }; + + # uses network.pkgs + "default_pkgs" = { config, pkgs, ... }: { + boot.isContainer = true; + }; + + # uses vpsfPkgs and vpsadminos + "vpsadminos" = { config, pkgs, ... }: { + boot.zfs.pools = { + tank = { + }; + }; + + deployment = { + nixPath = [ + { prefix = "nixpkgs"; path = vpsfPkgs; } + { prefix = "vpsadminos"; path = vpsadminos; } + ]; + importPath = "${vpsadminos}/os/default.nix"; + }; + }; + + "custom" = { config, pkgs, ... }: { + boot.isContainer = true; + + deployment = { + nixPath = [ + { prefix = "nixpkgs"; path = vpsfPkgs; } + ]; + }; + }; + + /* + "old" = { config, pkgs, ... }: { + boot.isContainer = true; + + deployment = { + nixPath = [ + { prefix = "nixpkgs"; path = oldPkgs.path; } + ]; + }; + }; + */ +}