Compare commits

..

2 commits

8 changed files with 36 additions and 68 deletions

View file

@ -3,7 +3,10 @@
"hello"
"cowsay"
];
pathToRoot = ../../..;
pathToRoot = builtins.path {
path = ../../..;
name = "root";
};
pathFromRoot = "/deployment/check/data-model-ssh";
useFlake = true;
}

View file

@ -5,7 +5,10 @@
"peertube"
"pixelfed"
];
pathToRoot = ../../..;
pathToRoot = builtins.path {
path = ../../..;
name = "root";
};
pathFromRoot = "/deployment/check/data-model-ssh";
enableAcme = true;
useFlake = true;

View file

@ -7,10 +7,7 @@
}@args:
let
# self = ./data-model.nix;
self = "deployment/check/common/data-model.nix";
# args = { inherit config system inputs sources; };
# self args
inherit (sources) nixpkgs;
pkgs = import nixpkgs { inherit system; };
inherit (pkgs) lib;
@ -145,7 +142,6 @@ let
};
module = self;
inherit args deployment-name root-path;
# deployment-name = "";
};
};
};

View file

@ -2,7 +2,10 @@
targetMachines = [
"nixops4"
];
pathToRoot = ../../..;
pathToRoot = builtins.path {
path = ../../..;
name = "root";
};
pathFromRoot = "/deployment/check/data-model-ssh";
enableAcme = true;
useFlake = true;

View file

@ -2,7 +2,11 @@
targetMachines = [
"ssh"
];
pathToRoot = ../../..;
# stablize path, as just the path would yield distinct paths when applied multiple times
pathToRoot = builtins.path {
path = ../../..;
name = "root";
};
pathFromRoot = "/deployment/check/data-model-ssh";
enableAcme = true;
}

View file

@ -5,7 +5,10 @@
"peertube"
"pixelfed"
];
pathToRoot = ../../..;
pathToRoot = builtins.path {
path = ../../..;
name = "root";
};
pathFromRoot = "/deployment/check/data-model-ssh";
enableAcme = true;
useFlake = true;

View file

@ -92,12 +92,10 @@ let
type = types.path;
};
run = mkOption {
# type = types.path;
type = types.str;
# readOnly = true;
default =
let
# inherit (ssh-host.config) ssh nixos-configuration;
inherit (ssh-host.config)
ssh
module
@ -105,69 +103,37 @@ let
deployment-name
root-path
;
# inherit (ssh-host.config) ssh module args;
inherit (ssh) host username key-file;
# inherit (import ./nixos.nix {
# # inherit system;
# system = pkgs.system; # XXX recheck this is the right one
# configuration = nixos-configuration;
# # commandFn = outPath: '''';
# }) drv_path;
# command
environment = {
# inherit (ssh-host) host username key-file;
# inherit host username drv_path;
key_file = key-file;
deployment_name = deployment-name;
root_path = root-path;
system = pkgs.system; # XXX recheck this is the right one
# config_nix = nixos-configuration;
# config_tf = {};
# inherit host username;
inherit
host
username
module
args
# root_path
;
deployment_type = "ssh-host";
# module = ;
# args = ;
# deployment_name = ;
# deployment_type = ;
# root_path = builtins.toString ./..;
# root_path = ;
};
in
# error: cannot coerce a function to a string: «lambda mkNixosConfiguration @ /nix/store/ifj5ykvb5hv05m9qcr4r1aah4s4f9pdi-source/deployment/check/common/data-model.nix:106:15»
# ''
# env ${toString (lib.mapAttrsToList (k: v: lib.trace (if k == "config_nix" then v {} else k) "${k}='${v}'") environment)} ${./run/ssh-single-host/run.sh}";
# '';
# ''
# env ${toString (lib.mapAttrsToList (k: v: lib.trace k "${k}=${lib.strings.toJSON v}") environment)} ${./run/ssh-single-host/run.sh}";
# '';
# if v == null then toString v else
# lib.traceVal
# ''
# env ${toString (lib.mapAttrsToList (k: v: lib.trace k "${k}='${v}'") (lib.filterAttrs (_: v: v != null) environment))} ${./run/ssh-single-host/run.sh}
# '';
lib.traceVal ''
''
env ${
toString (
lib.mapAttrsToList (
k: v:
lib.trace k "${k}=\"${
"${k}=\"${
lib.replaceStrings [ "\"" ] [ "\\\\\"" ] (
if lib.isAttrs v then
lib.strings.toJSON v
else if lib.isPath v then
if lib.isPath v || builtins.isNull v then
toString v
else
else if lib.isString v then
v
else
lib.strings.toJSON v
)
}\""
) (lib.filterAttrs (_: v: v != null) environment)
) environment
)
} bash ./deployment/run/ssh-single-host/run.sh
'';

View file

@ -1,35 +1,26 @@
#! /usr/bin/env bash
set -xeuo pipefail
declare username host system module args deployment_name deployment_type args #key_file root_path
declare username host system module args deployment_name deployment_type args key_file root_path
# DEPLOY
sshOpts=(
-o BatchMode=yes
-o StrictHostKeyChecking=no
# TODO set key for production
# ${if key-file == null then "" else "-i ${key-file}"}
# NOTE the below options are for tests
-o ConnectTimeout=1
-o ServerAliveInterval=1
)
if [[ -n "$key_file" ]]; then
sshOpts+=(
-i "$key_file"
)
fi
destination="$username@$host"
# echo "$cwd/deployment"
# ls "$cwd/deployment"
# echo "$args"
root=$(echo "$args" | jq -r '.config.pathToRoot')
# echo "$root/deployment/nixos.nix"
# ls "$root/deployment/nixos.nix"
# FIXME: ensure [[ $root_path == $root ]] so i could just rely on stuff from /deployment/data-model.nix
# cwd=$root_path
cwd=$root
command=(nix-instantiate --show-trace --expr "
import $cwd/deployment/nixos.nix {
import $root_path/deployment/nixos.nix {
system = \"$system\";
configuration = (import \"$cwd/$module\" (builtins.fromJSON ''$args'')).$deployment_name.$deployment_type.nixos-configuration;
configuration = (import \"$root_path/$module\" (builtins.fromJSON ''$args'')).$deployment_name.$deployment_type.nixos-configuration;
}
")
@ -38,7 +29,6 @@ command=(nix-instantiate --show-trace --expr "
"${command[@]}" -A out_path
# get the realized derivation to deploy
# "${command[@]}" --show-trace --eval --strict --json | jq -r '.command')"
outPath=$(nix-store --realize "$("${command[@]}" --show-trace --eval --strict --json | jq -r '.drv_path')")
# deploy the config by nix-copy-closure
NIX_SSHOPTS="${sshOpts[*]}" nix-copy-closure --to "$destination" "$outPath" --gzip --use-substitutes