From a50966a8ea5c50aedcf09335341cdb51ff7ca783 Mon Sep 17 00:00:00 2001 From: arcnmx Date: Sat, 13 Jan 2024 11:11:29 -0800 Subject: [PATCH] feat: lazy devshell eval --- {nixos => ci}/deploy.sh | 4 ++++ devShell.nix | 12 ++++-------- flake.nix | 1 + modules/meta/packages.nix | 19 +++++++++++++++++++ 4 files changed, 28 insertions(+), 8 deletions(-) rename {nixos => ci}/deploy.sh (96%) create mode 100644 modules/meta/packages.nix diff --git a/nixos/deploy.sh b/ci/deploy.sh similarity index 96% rename from nixos/deploy.sh rename to ci/deploy.sh index 2709549c..f8c100e5 100755 --- a/nixos/deploy.sh +++ b/ci/deploy.sh @@ -7,6 +7,10 @@ NF_HOST=${NF_HOST-tewi} NIXOS_TOPLEVEL=network.nodes.$NF_HOST.system.build.toplevel NF_ADDR=${NF_ADDR-${NF_HOST}.local} +if [[ $# -eq 0 ]]; then + set -- "" +fi + if [[ $1 = tarball ]]; then shift set -- build "$@" diff --git a/devShell.nix b/devShell.nix index 135056bf..9200fa4c 100644 --- a/devShell.nix +++ b/devShell.nix @@ -1,11 +1,7 @@ { inputs, system }: let meta = import ./meta.nix { inherit inputs system; }; - config = meta; inherit (meta) pkgs; - inherit (pkgs) lib; - inherit (lib.options) optional; - inherit (lib.attrsets) attrValues; nf-actions = pkgs.writeShellScriptBin "nf-actions" '' NF_CONFIG_FILES=($NF_CONFIG_ROOT/ci/{nodes,flake-cron}.nix) for f in "''${NF_CONFIG_FILES[@]}"; do @@ -14,13 +10,13 @@ let done ''; nf-actions-test = pkgs.writeShellScriptBin "nf-actions-test" '' - nix run --argstr config "$NF_CONFIG_ROOT/ci/nodes.nix" -f '${inputs.ci}' job.tewi.test + exec nix run --argstr config "$NF_CONFIG_ROOT/ci/nodes.nix" -f '${inputs.ci}' job.tewi.test ''; nf-update = pkgs.writeShellScriptBin "nf-update" '' - nix flake update + exec nix flake update "$@" ''; nf-deploy = pkgs.writeShellScriptBin "nf-deploy" '' - exec /usr/bin/env bash ${./nixos/deploy.sh} "$@" + exec nix run ''${FLAKE_OPTS-} ''$NF_CONFIG_ROOT#nf-deploy -- "$@" ''; in pkgs.mkShell { @@ -33,7 +29,7 @@ pkgs.mkShell { nf-deploy ]; shellHook = '' - export NIX_BIN_DIR=${pkgs.nix}/bin + export NIX_BIN_DIR=$(dirname $(readlink -f $(type -P nix))) export HOME_UID=$(id -u) export HOME_USER=$(id -un) export CI_PLATFORM="impure" diff --git a/flake.nix b/flake.nix index 838f3626..3abdd083 100644 --- a/flake.nix +++ b/flake.nix @@ -39,6 +39,7 @@ (system: rec { devShells.default = import ./devShell.nix {inherit system inputs;}; legacyPackages = import ./meta.nix {inherit system inputs;}; + inherit (legacyPackages.outputs) packages; }); in providedSystems diff --git a/modules/meta/packages.nix b/modules/meta/packages.nix new file mode 100644 index 00000000..b6ba312d --- /dev/null +++ b/modules/meta/packages.nix @@ -0,0 +1,19 @@ +{ + lib, + pkgs, + ... +}: let + inherit (lib.options) mkOption; + inherit (lib.types) attrsOf package; +in { + options.outputs.packages = mkOption { + type = attrsOf package; + default = { }; + }; + + config.outputs.packages = { + nf-deploy = pkgs.writeShellScriptBin "nf-deploy" '' + exec ${pkgs.runtimeShell} ${../../ci/deploy.sh} "$@" + ''; + }; +}