Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow per deployment.nixPath .importPath #55

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions data/eval-machines.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 <nixpkgs> correctly
importTarget = lib.attrByPath [ "deployment" "importPath" ] <nixpkgs/nixos/lib/eval-config.nix> (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";
Expand Down Expand Up @@ -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);
}
);

Expand All @@ -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 ''
Expand Down
19 changes: 19 additions & 0 deletions data/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 <nixpkgs/nixos/lib/eval-config.nix>
'';
};

buildOnly = mkOption {
type = bool;
default = false;
Expand Down
74 changes: 74 additions & 0 deletions examples/pinning.nix
Original file line number Diff line number Diff line change
@@ -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 <nixpkgs> {};

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; }
];
};
};
*/
}