From 9b6fafcb2d3e44fea56a9fca6248cbc9abc4bd37 Mon Sep 17 00:00:00 2001 From: DavHau Date: Tue, 19 Sep 2023 11:29:59 +0200 Subject: [PATCH] clan config: re-enable clan config --- flake.nix | 2 -- flakeModules/clan-config.nix | 42 ----------------------- nixosModules/clanCore/secrets/default.nix | 3 +- pkgs/clan-cli/clan_cli/__init__.py | 7 ++-- pkgs/clan-cli/clan_cli/config/__init__.py | 2 +- pkgs/clan-cli/default.nix | 14 +++----- pkgs/clan-cli/shell.nix | 3 -- 7 files changed, 9 insertions(+), 64 deletions(-) delete mode 100644 flakeModules/clan-config.nix diff --git a/flake.nix b/flake.nix index 79119ed36..7bd18b64d 100644 --- a/flake.nix +++ b/flake.nix @@ -31,8 +31,6 @@ ./formatter.nix ./templates/flake-module.nix - ./flakeModules/clan-config.nix - ./pkgs/flake-module.nix ./lib/flake-module.nix diff --git a/flakeModules/clan-config.nix b/flakeModules/clan-config.nix deleted file mode 100644 index 236d22592..000000000 --- a/flakeModules/clan-config.nix +++ /dev/null @@ -1,42 +0,0 @@ -{ ... } @ clanCore: { - flake.flakeModules.clan-config = { self, inputs, ... }: - let - - # take the default nixos configuration - options = self.nixosConfigurations.default.options; - - # this is actually system independent as it uses toFile - docs = inputs.nixpkgs.legacyPackages.x86_64-linux.nixosOptionsDoc { - inherit options; - }; - - optionsJSONFile = docs.optionsJSON.options; - - warnIfNoDefaultConfig = return: - if ! self ? nixosConfigurations.default - then - builtins.trace - "WARNING: .#nixosConfigurations.default could not be found. Please define it." - return - else return; - - in - { - flake.clanOptions = warnIfNoDefaultConfig optionsJSONFile; - - flake.clanSettings = self + /clan-settings.json; - - perSystem = { pkgs, ... }: { - devShells.clan-config = pkgs.mkShell { - packages = [ - clanCore.config.flake.packages.${pkgs.system}.clan-cli - ]; - shellHook = '' - export CLAN_OPTIONS_FILE=$(nix eval --raw .#clanOptions) - export XDG_DATA_DIRS="${clanCore.config.flake.packages.${pkgs.system}.clan-cli}/share''${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}" - export fish_complete_path="${clanCore.config.flake.packages.${pkgs.system}.clan-cli}/share/fish/vendor_completions.d''${fish_complete_path:+:$fish_complete_path}" - ''; - }; - }; - }; -} diff --git a/nixosModules/clanCore/secrets/default.nix b/nixosModules/clanCore/secrets/default.nix index 700f5d078..44fa757de 100644 --- a/nixosModules/clanCore/secrets/default.nix +++ b/nixosModules/clanCore/secrets/default.nix @@ -62,7 +62,8 @@ default = "machines/${config.clanCore.machineName}/facts/${fact.config._module.args.name}"; }; value = lib.mkOption { - default = builtins.readFile "${config.clanCore.clanDir}/fact.config.path"; + defaultText = lib.literalExpression "\${config.clanCore.clanDir}/\${fact.config.path}"; + default = builtins.readFile "${config.clanCore.clanDir}/${fact.config.path}"; }; }; })); diff --git a/pkgs/clan-cli/clan_cli/__init__.py b/pkgs/clan-cli/clan_cli/__init__.py index 0eb6dd527..f67bee800 100644 --- a/pkgs/clan-cli/clan_cli/__init__.py +++ b/pkgs/clan-cli/clan_cli/__init__.py @@ -1,5 +1,4 @@ import argparse -import os import sys from types import ModuleType from typing import Optional @@ -22,10 +21,8 @@ def create_parser(prog: Optional[str] = None) -> argparse.ArgumentParser: parser_create = subparsers.add_parser("create", help="create a clan flake") create.register_parser(parser_create) - # DISABLED: this currently crashes if a flake does not define .#clanOptions - if os.environ.get("CLAN_OPTIONS_FILE") is not None: - parser_config = subparsers.add_parser("config", help="set nixos configuration") - config.register_parser(parser_config) + parser_config = subparsers.add_parser("config", help="set nixos configuration") + config.register_parser(parser_config) parser_ssh = subparsers.add_parser("ssh", help="ssh to a remote machine") ssh_cli.register_parser(parser_ssh) diff --git a/pkgs/clan-cli/clan_cli/config/__init__.py b/pkgs/clan-cli/clan_cli/config/__init__.py index d81fbc2ca..a38385559 100644 --- a/pkgs/clan-cli/clan_cli/config/__init__.py +++ b/pkgs/clan-cli/clan_cli/config/__init__.py @@ -286,7 +286,7 @@ def register_parser( # add single positional argument for the option (e.g. "foo.bar") parser.add_argument( "option", - help="Option to configure", + help="Option to read or set", type=str, ) diff --git a/pkgs/clan-cli/default.nix b/pkgs/clan-cli/default.nix index 1f43eb45b..f41152fff 100644 --- a/pkgs/clan-cli/default.nix +++ b/pkgs/clan-cli/default.nix @@ -22,9 +22,6 @@ , ui-assets }: let - # This provides dummy options for testing clan config and prevents it from - # evaluating the flake .# - CLAN_OPTIONS_FILE = ./clan_cli/config/jsonschema/options.json; dependencies = [ argcomplete # optional dependency: if not enabled, shell completion will not work @@ -54,9 +51,9 @@ let ''; nixpkgs = runCommand "nixpkgs" { nativeBuildInputs = [ pkgs.nix ]; } '' mkdir $out - mkdir -p $out/unfree - cat > $out/unfree/default.nix < $out/unfree/default.nix < $out/flake.nix << EOF { @@ -81,8 +78,6 @@ python3.pkgs.buildPythonPackage { src = source; format = "pyproject"; - inherit CLAN_OPTIONS_FILE; - nativeBuildInputs = [ setuptools installShellFiles @@ -93,12 +88,11 @@ python3.pkgs.buildPythonPackage { { nativeBuildInputs = [ age zerotierone bubblewrap sops nix openssh rsync stdenv.cc ]; } '' - export CLAN_OPTIONS_FILE="${CLAN_OPTIONS_FILE}" cp -r ${source} ./src chmod +w -R ./src cd ./src - export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1 + export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1 ${checkPython}/bin/python -m pytest -m "not impure" -s ./tests touch $out ''; diff --git a/pkgs/clan-cli/shell.nix b/pkgs/clan-cli/shell.nix index f0ff0d7d0..f95340cbf 100644 --- a/pkgs/clan-cli/shell.nix +++ b/pkgs/clan-cli/shell.nix @@ -20,9 +20,6 @@ mkShell { pythonWithDeps ]; # sets up an editable install and add enty points to $PATH - # This provides dummy options for testing clan config and prevents it from - # evaluating the flake .# - CLAN_OPTIONS_FILE = ./clan_cli/config/jsonschema/options.json; PYTHONPATH = "${pythonWithDeps}/${pythonWithDeps.sitePackages}"; PYTHONBREAKPOINT = "ipdb.set_trace";