forked from fediversity/fediversity
Compare commits
2 commits
a2a4977139
...
18babb5a7f
| Author | SHA1 | Date | |
|---|---|---|---|
| 18babb5a7f | |||
| ab1b48d2e7 |
16 changed files with 392 additions and 336 deletions
|
|
@ -1,257 +0,0 @@
|
|||
{
|
||||
config,
|
||||
system,
|
||||
inputs ? (import ../../../default.nix { }).inputs, # XXX can't be serialized
|
||||
sources ? import ../../../npins,
|
||||
...
|
||||
}@args:
|
||||
|
||||
let
|
||||
# having this module's location (`self`) and (serializable) `args`, we know
|
||||
# enough to make it re-call itself to extract different info elsewhere later.
|
||||
# we use this to make a deployment script using the desired nixos config,
|
||||
# which would otherwise not be serializable, while nix also makes it hard to
|
||||
# produce its derivation to pass thru without a `nix-instantiate` call,
|
||||
# which in turn would need to be passed the (unserializable) nixos config.
|
||||
self = "deployment/check/common/data-model.nix";
|
||||
inherit (sources) nixpkgs;
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
inherit (pkgs) lib;
|
||||
deployment-config = config;
|
||||
inherit (deployment-config)
|
||||
nodeName
|
||||
pathToRoot
|
||||
targetSystem
|
||||
sshOpts
|
||||
httpBackend
|
||||
;
|
||||
inherit (lib) mkOption types;
|
||||
eval =
|
||||
module:
|
||||
(lib.evalModules {
|
||||
specialArgs = {
|
||||
inherit pkgs inputs;
|
||||
};
|
||||
modules = [
|
||||
module
|
||||
../../data-model.nix
|
||||
];
|
||||
}).config;
|
||||
fediversity = eval (
|
||||
{ config, ... }:
|
||||
{
|
||||
config = {
|
||||
resources.login-shell = {
|
||||
description = "The operator needs to be able to log into the shell";
|
||||
request =
|
||||
{ ... }:
|
||||
{
|
||||
_class = "fediversity-resource-request";
|
||||
options = {
|
||||
wheel = mkOption {
|
||||
description = "Whether the login user needs root permissions";
|
||||
type = types.bool;
|
||||
default = false;
|
||||
};
|
||||
packages = mkOption {
|
||||
description = "Packages that need to be available in the user environment";
|
||||
type = with types; attrsOf package;
|
||||
};
|
||||
};
|
||||
};
|
||||
policy =
|
||||
{ config, ... }:
|
||||
{
|
||||
_class = "fediversity-resource-policy";
|
||||
options = {
|
||||
username = mkOption {
|
||||
description = "Username for the operator";
|
||||
type = types.str; # TODO: use the proper constraints from NixOS
|
||||
};
|
||||
wheel = mkOption {
|
||||
description = "Whether to allow login with root permissions";
|
||||
type = types.bool;
|
||||
default = false;
|
||||
};
|
||||
};
|
||||
config = {
|
||||
resource-type = types.raw; # TODO: splice out the user type from NixOS
|
||||
apply =
|
||||
requests:
|
||||
let
|
||||
# Filter out requests that need wheel if policy doesn't allow it
|
||||
validRequests = lib.filterAttrs (
|
||||
_name: req: !req.login-shell.wheel || config.wheel
|
||||
) requests.resources;
|
||||
in
|
||||
lib.optionalAttrs (validRequests != { }) {
|
||||
${config.username} = {
|
||||
isNormalUser = true;
|
||||
packages =
|
||||
with lib;
|
||||
attrValues (concatMapAttrs (_name: request: request.login-shell.packages) validRequests);
|
||||
extraGroups = lib.optional config.wheel "wheel";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
applications.hello =
|
||||
{ ... }:
|
||||
{
|
||||
description = ''Command-line tool that will print "Hello, world!" on the terminal'';
|
||||
module =
|
||||
{ ... }:
|
||||
{
|
||||
options.enable = lib.mkEnableOption "Hello in the shell";
|
||||
};
|
||||
implementation = cfg: {
|
||||
resources = lib.optionalAttrs cfg.enable {
|
||||
hello.login-shell.packages.hello = pkgs.hello;
|
||||
};
|
||||
};
|
||||
};
|
||||
environments =
|
||||
let
|
||||
mkNixosConfiguration =
|
||||
environment: requests:
|
||||
{ ... }:
|
||||
{
|
||||
imports = [
|
||||
./data-model-options.nix
|
||||
../common/sharedOptions.nix
|
||||
../common/targetNode.nix
|
||||
"${nixpkgs}/nixos/modules/profiles/qemu-guest.nix"
|
||||
];
|
||||
|
||||
users.users = environment.config.resources."operator-environment".login-shell.apply {
|
||||
resources = lib.filterAttrs (_name: value: value ? login-shell) (
|
||||
lib.concatMapAttrs (
|
||||
k': req: lib.mapAttrs' (k: lib.nameValuePair "${k'}.${k}") req.resources
|
||||
) requests
|
||||
);
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
single-nixos-vm-ssh = environment: {
|
||||
resources."operator-environment".login-shell.username = "operator";
|
||||
implementation =
|
||||
{
|
||||
required-resources,
|
||||
deployment-name,
|
||||
}:
|
||||
{
|
||||
ssh-host = {
|
||||
nixos-configuration = mkNixosConfiguration environment required-resources;
|
||||
system = targetSystem;
|
||||
ssh = {
|
||||
username = "root";
|
||||
host = nodeName;
|
||||
key-file = null;
|
||||
inherit sshOpts;
|
||||
};
|
||||
module = self;
|
||||
inherit args deployment-name;
|
||||
root-path = pathToRoot;
|
||||
};
|
||||
};
|
||||
};
|
||||
single-nixos-vm-nixops4 = environment: {
|
||||
resources."operator-environment".login-shell.username = "operator";
|
||||
implementation =
|
||||
{
|
||||
required-resources,
|
||||
...
|
||||
}:
|
||||
{
|
||||
nixops4 =
|
||||
{ providers, ... }:
|
||||
{
|
||||
providers = {
|
||||
inherit (inputs.nixops4.modules.nixops4Provider) local;
|
||||
};
|
||||
resources.${nodeName} = {
|
||||
type = providers.local.exec;
|
||||
imports = [
|
||||
inputs.nixops4-nixos.modules.nixops4Resource.nixos
|
||||
../common/targetResource.nix
|
||||
];
|
||||
nixos.module = mkNixosConfiguration environment required-resources;
|
||||
_module.args = { inherit inputs sources; };
|
||||
inherit (deployment-config) nodeName pathToRoot pathFromRoot;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
single-nixos-vm-tf = environment: {
|
||||
resources."operator-environment".login-shell.username = "operator";
|
||||
implementation =
|
||||
{
|
||||
required-resources,
|
||||
deployment-name,
|
||||
}:
|
||||
{
|
||||
tf-host = {
|
||||
nixos-configuration = mkNixosConfiguration environment required-resources;
|
||||
system = targetSystem;
|
||||
ssh = {
|
||||
username = "root";
|
||||
host = nodeName;
|
||||
key-file = null;
|
||||
inherit sshOpts;
|
||||
};
|
||||
module = self;
|
||||
inherit args deployment-name httpBackend;
|
||||
root-path = pathToRoot;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
options = {
|
||||
"example-configuration" = mkOption {
|
||||
type = config.configuration;
|
||||
default = {
|
||||
enable = true;
|
||||
applications.hello.enable = true;
|
||||
};
|
||||
};
|
||||
"ssh-deployment" =
|
||||
let
|
||||
env = config.environments."single-nixos-vm-ssh";
|
||||
in
|
||||
mkOption {
|
||||
type = env.resource-mapping.output-type;
|
||||
default = env.deployment {
|
||||
deployment-name = "ssh-deployment";
|
||||
configuration = config."example-configuration";
|
||||
};
|
||||
};
|
||||
"nixops4-deployment" =
|
||||
let
|
||||
env = config.environments."single-nixos-vm-nixops4";
|
||||
in
|
||||
mkOption {
|
||||
type = env.resource-mapping.output-type;
|
||||
default = env.deployment {
|
||||
deployment-name = "nixops4-deployment";
|
||||
configuration = config."example-configuration";
|
||||
};
|
||||
};
|
||||
"tf-deployment" =
|
||||
let
|
||||
env = config.environments."single-nixos-vm-tf";
|
||||
in
|
||||
mkOption {
|
||||
type = env.resource-mapping.output-type;
|
||||
default = env.deployment {
|
||||
deployment-name = "tf-deployment";
|
||||
configuration = config."example-configuration";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
in
|
||||
fediversity
|
||||
91
deployment/check/common/model.nix
Normal file
91
deployment/check/common/model.nix
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
in
|
||||
{
|
||||
config = {
|
||||
resources.login-shell = {
|
||||
description = "The operator needs to be able to log into the shell";
|
||||
request =
|
||||
{ ... }:
|
||||
{
|
||||
_class = "fediversity-resource-request";
|
||||
options = {
|
||||
wheel = mkOption {
|
||||
description = "Whether the login user needs root permissions";
|
||||
type = types.bool;
|
||||
default = false;
|
||||
};
|
||||
packages = mkOption {
|
||||
description = "Packages that need to be available in the user environment";
|
||||
type = with types; attrsOf package;
|
||||
};
|
||||
};
|
||||
};
|
||||
policy =
|
||||
{ config, ... }:
|
||||
{
|
||||
_class = "fediversity-resource-policy";
|
||||
options = {
|
||||
username = mkOption {
|
||||
description = "Username for the operator";
|
||||
type = types.str; # TODO: use the proper constraints from NixOS
|
||||
};
|
||||
wheel = mkOption {
|
||||
description = "Whether to allow login with root permissions";
|
||||
type = types.bool;
|
||||
default = false;
|
||||
};
|
||||
};
|
||||
config = {
|
||||
resource-type = types.raw; # TODO: splice out the user type from NixOS
|
||||
apply =
|
||||
requests:
|
||||
let
|
||||
# Filter out requests that need wheel if policy doesn't allow it
|
||||
validRequests = lib.filterAttrs (
|
||||
_name: req: !req.login-shell.wheel || config.wheel
|
||||
) requests.resources;
|
||||
in
|
||||
lib.optionalAttrs (validRequests != { }) {
|
||||
${config.username} = {
|
||||
isNormalUser = true;
|
||||
packages =
|
||||
with lib;
|
||||
attrValues (concatMapAttrs (_name: request: request.login-shell.packages) validRequests);
|
||||
extraGroups = lib.optional config.wheel "wheel";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
applications.hello =
|
||||
{ ... }:
|
||||
{
|
||||
description = ''Command-line tool that will print "Hello, world!" on the terminal'';
|
||||
module =
|
||||
{ ... }:
|
||||
{
|
||||
options.enable = lib.mkEnableOption "Hello in the shell";
|
||||
};
|
||||
implementation = cfg: {
|
||||
resources = lib.optionalAttrs cfg.enable {
|
||||
hello.login-shell.packages.hello = pkgs.hello;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
options."example-configuration" = mkOption {
|
||||
type = config.configuration;
|
||||
default = {
|
||||
enable = true;
|
||||
applications.hello.enable = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
25
deployment/check/common/utils.nix
Normal file
25
deployment/check/common/utils.nix
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
lib,
|
||||
sources ? import ../../../npins,
|
||||
...
|
||||
}:
|
||||
{
|
||||
mkNixosConfiguration =
|
||||
environment: requests:
|
||||
{ ... }:
|
||||
{
|
||||
imports = [
|
||||
../common/sharedOptions.nix
|
||||
../common/targetNode.nix
|
||||
"${sources.nixpkgs}/nixos/modules/profiles/qemu-guest.nix"
|
||||
];
|
||||
|
||||
users.users = environment.config.resources."operator-environment".login-shell.apply {
|
||||
resources = lib.filterAttrs (_name: value: value ? login-shell) (
|
||||
lib.concatMapAttrs (
|
||||
k': req: lib.mapAttrs' (k: lib.nameValuePair "${k'}.${k}") req.resources
|
||||
) requests
|
||||
);
|
||||
};
|
||||
};
|
||||
}
|
||||
64
deployment/check/data-model-nixops4/data-model.nix
Normal file
64
deployment/check/data-model-nixops4/data-model.nix
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
{
|
||||
config,
|
||||
system,
|
||||
inputs,
|
||||
sources ? import ../../../npins,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (sources) nixpkgs;
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
inherit (pkgs) lib;
|
||||
inherit (pkgs.callPackage ../common/utils.nix { }) mkNixosConfiguration;
|
||||
inherit (config)
|
||||
nodeName
|
||||
pathFromRoot
|
||||
pathToRoot
|
||||
;
|
||||
in
|
||||
(pkgs.callPackage ../../utils.nix { inherit inputs; }).evalModel (
|
||||
{ config, ... }:
|
||||
{
|
||||
imports = [ ../common/model.nix ];
|
||||
config = {
|
||||
environments.default = environment: {
|
||||
resources."operator-environment".login-shell.username = "operator";
|
||||
implementation =
|
||||
{
|
||||
required-resources,
|
||||
...
|
||||
}:
|
||||
{
|
||||
nixops4 =
|
||||
{ providers, ... }:
|
||||
{
|
||||
providers = {
|
||||
inherit (inputs.nixops4.modules.nixops4Provider) local;
|
||||
};
|
||||
resources.${nodeName} = {
|
||||
type = providers.local.exec;
|
||||
imports = [
|
||||
inputs.nixops4-nixos.modules.nixops4Resource.nixos
|
||||
../common/targetResource.nix
|
||||
];
|
||||
nixos.module = mkNixosConfiguration environment required-resources;
|
||||
_module.args = { inherit inputs sources; };
|
||||
inherit nodeName pathToRoot pathFromRoot;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
options.default =
|
||||
let
|
||||
env = config.environments.default;
|
||||
in
|
||||
lib.mkOption {
|
||||
type = env.resource-mapping.output-type;
|
||||
default = env.deployment {
|
||||
deployment-name = "default";
|
||||
configuration = config."example-configuration";
|
||||
};
|
||||
};
|
||||
}
|
||||
)
|
||||
|
|
@ -17,13 +17,13 @@
|
|||
];
|
||||
|
||||
nixops4Deployments.check-deployment-model =
|
||||
(import ./deployment/check/common/data-model.nix {
|
||||
(import ./deployment/check/data-model-nixops4/data-model.nix {
|
||||
inherit system inputs;
|
||||
config = {
|
||||
inherit (import ./deployment/check/data-model-nixops4/constants.nix) pathToRoot pathFromRoot;
|
||||
nodeName = "nixops4";
|
||||
};
|
||||
})."nixops4-deployment".nixops4;
|
||||
}).default.nixops4;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,17 +6,15 @@
|
|||
}:
|
||||
{
|
||||
_class = "nixosTest";
|
||||
imports = [
|
||||
../common/data-model-options.nix
|
||||
];
|
||||
|
||||
name = "deployment-model";
|
||||
sourceFileset = lib.fileset.unions [
|
||||
../../data-model.nix
|
||||
../../function.nix
|
||||
../common/data-model.nix
|
||||
../common/data-model-options.nix
|
||||
../../utils.nix
|
||||
../common/model.nix
|
||||
../common/utils.nix
|
||||
./constants.nix
|
||||
./data-model.nix
|
||||
(config.pathToCwd + "/flake-under-test.nix")
|
||||
];
|
||||
|
||||
|
|
|
|||
62
deployment/check/data-model-ssh/data-model.nix
Normal file
62
deployment/check/data-model-ssh/data-model.nix
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
{
|
||||
config,
|
||||
system,
|
||||
sources ? import ../../../npins,
|
||||
...
|
||||
}@args:
|
||||
let
|
||||
self = "deployment/check/data-model-ssh/data-model.nix";
|
||||
inherit (sources) nixpkgs;
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
inherit (pkgs) lib;
|
||||
inherit (pkgs.callPackage ../common/utils.nix { }) mkNixosConfiguration;
|
||||
inherit (config)
|
||||
nodeName
|
||||
pathToRoot
|
||||
targetSystem
|
||||
sshOpts
|
||||
;
|
||||
in
|
||||
(pkgs.callPackage ../../utils.nix { }).evalModel (
|
||||
{ config, ... }:
|
||||
{
|
||||
imports = [ ../common/model.nix ];
|
||||
config = {
|
||||
environments.default = environment: {
|
||||
resources."operator-environment".login-shell.username = "operator";
|
||||
implementation =
|
||||
{
|
||||
required-resources,
|
||||
deployment-name,
|
||||
...
|
||||
}:
|
||||
{
|
||||
ssh-host = {
|
||||
nixos-configuration = mkNixosConfiguration environment required-resources;
|
||||
system = targetSystem;
|
||||
ssh = {
|
||||
username = "root";
|
||||
host = nodeName;
|
||||
key-file = null;
|
||||
inherit sshOpts;
|
||||
};
|
||||
module = self;
|
||||
inherit args deployment-name;
|
||||
root-path = pathToRoot;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
options.default =
|
||||
let
|
||||
env = config.environments.default;
|
||||
in
|
||||
lib.mkOption {
|
||||
type = env.resource-mapping.output-type;
|
||||
default = env.deployment {
|
||||
deployment-name = "default";
|
||||
configuration = config."example-configuration";
|
||||
};
|
||||
};
|
||||
}
|
||||
)
|
||||
|
|
@ -6,23 +6,21 @@
|
|||
let
|
||||
inherit (pkgs) system;
|
||||
nodeName = "ssh";
|
||||
deployment-config = {
|
||||
inherit nodeName;
|
||||
inherit (import ./constants.nix) pathToRoot;
|
||||
targetSystem = system;
|
||||
sshOpts = [ ];
|
||||
};
|
||||
deploy =
|
||||
(import ../common/data-model.nix {
|
||||
(import ./data-model.nix {
|
||||
inherit system;
|
||||
config = deployment-config;
|
||||
# opt not to pass `inputs`, as we could only pass serializable arguments through to its self-call
|
||||
})."ssh-deployment".ssh-host.run;
|
||||
config = {
|
||||
inherit nodeName;
|
||||
inherit (import ./constants.nix) pathToRoot;
|
||||
targetSystem = system;
|
||||
sshOpts = [ ];
|
||||
};
|
||||
}).default.ssh-host.run;
|
||||
in
|
||||
{
|
||||
_class = "nixosTest";
|
||||
imports = [
|
||||
../common/data-model-options.nix
|
||||
./options.nix
|
||||
];
|
||||
|
||||
name = "deployment-model";
|
||||
|
|
@ -33,8 +31,7 @@ in
|
|||
../../run/ssh-single-host/run.sh
|
||||
../../../npins/default.nix
|
||||
../../../npins/sources.json
|
||||
../common/data-model.nix
|
||||
../common/data-model-options.nix
|
||||
./options.nix
|
||||
./constants.nix
|
||||
];
|
||||
|
||||
|
|
|
|||
15
deployment/check/data-model-ssh/options.nix
Normal file
15
deployment/check/data-model-ssh/options.nix
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
in
|
||||
{
|
||||
options = {
|
||||
targetSystem = mkOption {
|
||||
type = types.str;
|
||||
description = "name of the host to deploy to";
|
||||
};
|
||||
};
|
||||
}
|
||||
62
deployment/check/data-model-tf/data-model.nix
Normal file
62
deployment/check/data-model-tf/data-model.nix
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
{
|
||||
config,
|
||||
system,
|
||||
sources ? import ../../../npins,
|
||||
...
|
||||
}@args:
|
||||
let
|
||||
self = "deployment/check/data-model-tf/data-model.nix";
|
||||
inherit (sources) nixpkgs;
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
inherit (pkgs) lib;
|
||||
inherit (pkgs.callPackage ../common/utils.nix { }) mkNixosConfiguration;
|
||||
inherit (config)
|
||||
nodeName
|
||||
pathToRoot
|
||||
targetSystem
|
||||
sshOpts
|
||||
httpBackend
|
||||
;
|
||||
in
|
||||
(pkgs.callPackage ../../utils.nix { }).evalModel (
|
||||
{ config, ... }:
|
||||
{
|
||||
imports = [ ../common/model.nix ];
|
||||
config = {
|
||||
environments.default = environment: {
|
||||
resources."operator-environment".login-shell.username = "operator";
|
||||
implementation =
|
||||
{
|
||||
required-resources,
|
||||
deployment-name,
|
||||
}:
|
||||
{
|
||||
tf-host = {
|
||||
nixos-configuration = mkNixosConfiguration environment required-resources;
|
||||
system = targetSystem;
|
||||
ssh = {
|
||||
username = "root";
|
||||
host = nodeName;
|
||||
key-file = null;
|
||||
inherit sshOpts;
|
||||
};
|
||||
module = self;
|
||||
inherit args deployment-name httpBackend;
|
||||
root-path = pathToRoot;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
options.default =
|
||||
let
|
||||
env = config.environments.default;
|
||||
in
|
||||
lib.mkOption {
|
||||
type = env.resource-mapping.output-type;
|
||||
default = env.deployment {
|
||||
deployment-name = "default";
|
||||
configuration = config."example-configuration";
|
||||
};
|
||||
};
|
||||
}
|
||||
)
|
||||
|
|
@ -9,29 +9,27 @@ let
|
|||
inherit (import ./constants.nix) pathToRoot;
|
||||
nodeName = "target";
|
||||
backendPort = builtins.toString 8080;
|
||||
deployment-config = {
|
||||
inherit nodeName pathToRoot;
|
||||
targetSystem = system;
|
||||
sshOpts = [ ];
|
||||
httpBackend = rec {
|
||||
TF_HTTP_USERNAME = "basic";
|
||||
TF_HTTP_PASSWORD = "fake-secret";
|
||||
TF_HTTP_ADDRESS = "http://localhost:${backendPort}/state/project1/example";
|
||||
TF_HTTP_LOCK_ADDRESS = TF_HTTP_ADDRESS;
|
||||
TF_HTTP_UNLOCK_ADDRESS = TF_HTTP_ADDRESS;
|
||||
};
|
||||
};
|
||||
deploy =
|
||||
(import ../common/data-model.nix {
|
||||
(import ./data-model.nix {
|
||||
inherit system;
|
||||
config = deployment-config;
|
||||
# opt not to pass `inputs`, as we could only pass serializable arguments through to its self-call
|
||||
})."tf-deployment".tf-host.run;
|
||||
config = {
|
||||
inherit nodeName pathToRoot;
|
||||
targetSystem = system;
|
||||
sshOpts = [ ];
|
||||
httpBackend = rec {
|
||||
TF_HTTP_USERNAME = "basic";
|
||||
TF_HTTP_PASSWORD = "fake-secret";
|
||||
TF_HTTP_ADDRESS = "http://localhost:${backendPort}/state/project1/example";
|
||||
TF_HTTP_LOCK_ADDRESS = TF_HTTP_ADDRESS;
|
||||
TF_HTTP_UNLOCK_ADDRESS = TF_HTTP_ADDRESS;
|
||||
};
|
||||
};
|
||||
}).default.tf-host.run;
|
||||
in
|
||||
{
|
||||
_class = "nixosTest";
|
||||
imports = [
|
||||
../common/data-model-options.nix
|
||||
./options.nix
|
||||
];
|
||||
|
||||
name = "deployment-model";
|
||||
|
|
|
|||
|
|
@ -7,10 +7,6 @@ let
|
|||
in
|
||||
{
|
||||
options = {
|
||||
host = mkOption {
|
||||
type = types.str;
|
||||
description = "name of the host to deploy to";
|
||||
};
|
||||
targetSystem = mkOption {
|
||||
type = types.str;
|
||||
description = "name of the host to deploy to";
|
||||
|
|
@ -2,17 +2,7 @@ let
|
|||
inherit (import ../default.nix { }) pkgs inputs;
|
||||
inherit (pkgs) lib;
|
||||
inherit (lib) mkOption types;
|
||||
eval =
|
||||
module:
|
||||
(lib.evalModules {
|
||||
specialArgs = {
|
||||
inherit pkgs inputs;
|
||||
};
|
||||
modules = [
|
||||
module
|
||||
./data-model.nix
|
||||
];
|
||||
}).config;
|
||||
inherit (pkgs.callPackage ./utils.nix { inherit inputs; }) evalModel;
|
||||
inherit (inputs.nixops4.lib) mkDeployment;
|
||||
in
|
||||
{
|
||||
|
|
@ -30,7 +20,7 @@ in
|
|||
*/
|
||||
expr =
|
||||
let
|
||||
fediversity = eval (
|
||||
fediversity = evalModel (
|
||||
{ config, ... }:
|
||||
{
|
||||
config = {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
config,
|
||||
inputs,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
|
|
@ -18,16 +18,7 @@ let
|
|||
str
|
||||
submodule
|
||||
;
|
||||
toBash =
|
||||
v:
|
||||
lib.replaceStrings [ "\"" ] [ "\\\"" ] (
|
||||
if lib.isPath v || builtins.isNull v then
|
||||
toString v
|
||||
else if lib.isString v then
|
||||
v
|
||||
else
|
||||
lib.strings.toJSON v
|
||||
);
|
||||
inherit (pkgs.callPackage ./utils.nix { }) toBash;
|
||||
withPackages = packages: {
|
||||
makeWrapperArgs = [
|
||||
"--prefix"
|
||||
|
|
@ -45,6 +36,12 @@ let
|
|||
deployment-name,
|
||||
args,
|
||||
}:
|
||||
# having a `module` location and (serializable) `args`, we know
|
||||
# enough to call it again to extract different info elsewhere later.
|
||||
# we use this to make a deployment script using the desired nixos config,
|
||||
# which would otherwise not be serializable, while nix also makes it hard to
|
||||
# produce its derivation to pass thru without a `nix-instantiate` call,
|
||||
# which in turn would need to be passed the (unserializable) nixos config.
|
||||
builtins.toString (
|
||||
pkgs.writers.writeText "configuration.nix" ''
|
||||
import ${root-path}/deployment/nixos.nix {
|
||||
|
|
@ -135,6 +132,7 @@ let
|
|||
deployment-name = mkOption {
|
||||
description = "The name of the deployment for which to obtain the NixOS configuration.";
|
||||
type = types.str;
|
||||
default = "default";
|
||||
};
|
||||
root-path = mkOption {
|
||||
description = "The path to the root of the repository.";
|
||||
|
|
@ -460,9 +458,7 @@ in
|
|||
readOnly = true;
|
||||
default = submodule {
|
||||
options = {
|
||||
enable = lib.mkEnableOption {
|
||||
description = "your Fediversity configuration";
|
||||
};
|
||||
enable = lib.mkEnableOption "your Fediversity configuration";
|
||||
applications = lib.mapAttrs (
|
||||
_name: application:
|
||||
mkOption {
|
||||
|
|
|
|||
|
|
@ -5,17 +5,7 @@
|
|||
httpBackend,
|
||||
}:
|
||||
let
|
||||
# FIXME factor out
|
||||
toBash =
|
||||
v:
|
||||
lib.replaceStrings [ "\"" ] [ "\\\"" ] (
|
||||
if lib.isPath v || builtins.isNull v then
|
||||
toString v
|
||||
else if lib.isString v then
|
||||
v
|
||||
else
|
||||
lib.strings.toJSON v
|
||||
);
|
||||
inherit (pkgs.callPackage ../utils.nix { }) toBash;
|
||||
in
|
||||
pkgs.writeScriptBin "setup" ''
|
||||
set -e
|
||||
|
|
|
|||
29
deployment/utils.nix
Normal file
29
deployment/utils.nix
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
inputs ? null,
|
||||
...
|
||||
}:
|
||||
{
|
||||
evalModel =
|
||||
module:
|
||||
(lib.evalModules {
|
||||
specialArgs = {
|
||||
inherit pkgs inputs;
|
||||
};
|
||||
modules = [
|
||||
./data-model.nix
|
||||
module
|
||||
];
|
||||
}).config;
|
||||
toBash =
|
||||
v:
|
||||
lib.replaceStrings [ "\"" ] [ "\\\"" ] (
|
||||
if lib.isPath v || builtins.isNull v then
|
||||
toString v
|
||||
else if lib.isString v then
|
||||
v
|
||||
else
|
||||
lib.strings.toJSON v
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue