From 872f420399cc221a3f3a01cb021efeedd712a5a0 Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Wed, 30 Aug 2023 14:02:04 +0200 Subject: [PATCH 1/4] UI: search bar improvement. Bug: ESC doesnt work --- pkgs/ui/src/components/table/searchBar.tsx | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pkgs/ui/src/components/table/searchBar.tsx b/pkgs/ui/src/components/table/searchBar.tsx index 73f300fe4..c5ea2611d 100644 --- a/pkgs/ui/src/components/table/searchBar.tsx +++ b/pkgs/ui/src/components/table/searchBar.tsx @@ -33,12 +33,13 @@ export function SearchBar(props: SearchBarProps) { const debouncedSearch = useDebounce(search, 250); // Define a function to handle the Esc key press - const handleEsc = (event: any) => { + function handleEsc(event: React.KeyboardEvent) { if (event.key === "Escape") { + console.log("Escape key pressed"); setSearch(""); setFilteredList(tableData); } - }; + } useEffect(() => { if (debouncedSearch) { @@ -65,6 +66,7 @@ export function SearchBar(props: SearchBarProps) { { // do something with the selected value if (value === null) { @@ -81,18 +83,17 @@ export function SearchBar(props: SearchBarProps) { label="Search" variant="outlined" value={search} - onKeyDown={handleEsc} onChange={handleInputChange} autoComplete="nickname" InputProps={{ ...params.InputProps, - endAdornment: ( - - - - - - ), + // endAdornment: ( + // + // + // + // + // + // ), }} > {/* {suggestions.map((item, index) => ( From bad7d624bdf3f3d2ff759a3db1bf988366c38fc2 Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Wed, 30 Aug 2023 15:25:20 +0200 Subject: [PATCH 2/4] Improved Quickstart --- docs/quickstart.md | 101 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 76 insertions(+), 25 deletions(-) diff --git a/docs/quickstart.md b/docs/quickstart.md index 950e6783c..63cb208ca 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -28,34 +28,85 @@ If `.clan-flake` is missing, `clan-cli` will instead search for other indicators # Migrating Existing NixOS Configuration Flake -## Integrating with Existing NixOS Machines +Absolutely, let's break down the migration step by step, explaining each action in detail: -If you already manage NixOS machines using a flake, you can integrate them with the clan-core as shown in the example below: +#### Before You Begin -```nix -{ - description = "My custom NixOS flake"; +1. **Backup Your Current Configuration**: Always start by making a backup of your current NixOS configuration to ensure you can revert if needed. - inputs.clan-core.url = "git+https://git.clan.lol/clan/clan-core"; + ```shell + cp -r /etc/nixos ~/nixos-backup + ``` - outputs = { clan-core, ... }: { - nixosConfigurations = clan-core.lib.buildClan { - directory = ./.; - machines = { - turingmachine = { - nixpkgs.pkgs = nixpkgs.legacyPackages.aarch64-linux; - imports = [ - ./configuration.nix - ]; - }; - }; - }; - }; -} -``` +2. **Update Flake Inputs**: The patch adds a new input named `clan-core` to your `flake.nix`. This input points to a Git repository for Clan Core. Here's the addition: -In this configuration: + ```nix + inputs.clan-core = { + url = "git+https://git.clan.lol/clan/clan-core"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + ``` -- `description`: Provides a brief description of the flake. -- `inputs.clan-core.url`: Specifies the Clan Core template's repository URL. -- `nixosConfigurations`: Defines NixOS configurations, using Clan Core’s `buildClan` function to manage the machines. + - `url`: Specifies the Git repository URL for Clan Core. + - `inputs.nixpkgs.follows`: Tells Nix to use the same `nixpkgs` input as your main input (in this case, it follows `nixpkgs`). + +3. **Update Outputs**: Then modify the `outputs` section of your `flake.nix` to adapt to Clan Core's new provisioning method. The key changes are as follows: + + Add `clan-core` to the output + + ```diff + - outputs = { self, nixpkgs, }: + + outputs = { self, nixpkgs, clan-core }: + ``` + + Previous configuration: + + ```nix + nixosConfigurations.example-desktop = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ./configuration.nix + ]; + [...] + }; + ``` + + After change: + + ```nix + nixosConfigurations = clan-core.lib.buildClan { + directory = ./.; + machines = { + example-desktop = { + nixpkgs.hostPlatform = "x86_64-linux"; + imports = [ + ./configuration.nix + ]; + }; + }; + }; + ``` + + - `nixosConfigurations`: Defines NixOS configurations, using Clan Core’s `buildClan` function to manage the machines. + - Inside `machines`, a new machine configuration is defined (in this case, `example-desktop`). + - Inside `example-desktop` which is the target machine hostname, `nixpkgs.hostPlatform` specifies the host platform as `x86_64-linux`. + +4. **Rebuild and Switch**: Rebuild your NixOS configuration using the updated flake: + + ```shell + sudo nixos-rebuild switch --flake . + ``` + + - This command rebuilds and switches to the new configuration. Make sure to include the `--flake .` argument to use the current directory as the flake source. + +5. **Test Configuration**: Before rebooting, verify that your new configuration builds without errors or warnings. + +6. **Reboot**: If everything is fine, you can reboot your system to apply the changes: + + ```shell + sudo reboot + ``` + +7. **Verify**: After the reboot, confirm that your system is running with the new configuration, and all services and applications are functioning as expected. + +By following these steps, you've successfully migrated your NixOS Flake configuration to include the `clan-core` input and adapted the `outputs` section to work with Clan Core's new machine provisioning method. From d16bd000da8fcb4c2015f9020630a7b882d3d8f0 Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Wed, 30 Aug 2023 15:28:24 +0200 Subject: [PATCH 3/4] Improved quickstart.me --- flake.nix | 2 +- flakeModules/clan-config.nix | 8 ++++---- .../{clanCore => core}/flake-module.nix | 4 ++-- .../{clanCore => core}/secrets/default.nix | 4 ++-- .../{clanCore => core}/secrets/sops.nix | 20 +++++++++---------- nixosModules/{clanCore => core}/zerotier.nix | 4 ++-- pkgs/clan-cli/clan_cli/secrets/generate.py | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) rename nixosModules/{clanCore => core}/flake-module.nix (91%) rename nixosModules/{clanCore => core}/secrets/default.nix (92%) rename nixosModules/{clanCore => core}/secrets/sops.nix (70%) rename nixosModules/{clanCore => core}/zerotier.nix (95%) diff --git a/flake.nix b/flake.nix index 79119ed36..4b908bddf 100644 --- a/flake.nix +++ b/flake.nix @@ -37,7 +37,7 @@ ./lib/flake-module.nix ./nixosModules/flake-module.nix - ./nixosModules/clanCore/flake-module.nix + ./nixosModules/core/flake-module.nix ]; }); } diff --git a/flakeModules/clan-config.nix b/flakeModules/clan-config.nix index 236d22592..2d1cd5c87 100644 --- a/flakeModules/clan-config.nix +++ b/flakeModules/clan-config.nix @@ -1,4 +1,4 @@ -{ ... } @ clanCore: { +{ ... } @ core: { flake.flakeModules.clan-config = { self, inputs, ... }: let @@ -29,12 +29,12 @@ perSystem = { pkgs, ... }: { devShells.clan-config = pkgs.mkShell { packages = [ - clanCore.config.flake.packages.${pkgs.system}.clan-cli + core.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}" + export XDG_DATA_DIRS="${core.config.flake.packages.${pkgs.system}.clan-cli}/share''${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}" + export fish_complete_path="${core.config.flake.packages.${pkgs.system}.clan-cli}/share/fish/vendor_completions.d''${fish_complete_path:+:$fish_complete_path}" ''; }; }; diff --git a/nixosModules/clanCore/flake-module.nix b/nixosModules/core/flake-module.nix similarity index 91% rename from nixosModules/clanCore/flake-module.nix rename to nixosModules/core/flake-module.nix index da8fa0e63..55648bf64 100644 --- a/nixosModules/clanCore/flake-module.nix +++ b/nixosModules/core/flake-module.nix @@ -1,6 +1,6 @@ { self, inputs, lib, ... }: { - flake.nixosModules.clanCore = { pkgs, ... }: { - options.clanCore = { + flake.nixosModules.clan.core = { pkgs, ... }: { + options.clan.core = { clanDir = lib.mkOption { type = lib.types.str; description = '' diff --git a/nixosModules/clanCore/secrets/default.nix b/nixosModules/core/secrets/default.nix similarity index 92% rename from nixosModules/clanCore/secrets/default.nix rename to nixosModules/core/secrets/default.nix index f1128a327..1660de63c 100644 --- a/nixosModules/clanCore/secrets/default.nix +++ b/nixosModules/core/secrets/default.nix @@ -1,6 +1,6 @@ { config, lib, ... }: { - options.clanCore.secrets = lib.mkOption { + options.clan.core.secrets = lib.mkOption { type = lib.types.attrsOf (lib.types.submodule (secret: { options = { @@ -49,7 +49,7 @@ description = '' path to a fact which is generated by the generator ''; - default = "${config.clanCore.clanDir}/facts/${config.clanCore.machineName}/${fact.config._module.args.name}"; + default = "${config.clan.core.clanDir}/facts/${config.clan.core.machineName}/${fact.config._module.args.name}"; }; value = lib.mkOption { default = builtins.readFile fact.config.path; diff --git a/nixosModules/clanCore/secrets/sops.nix b/nixosModules/core/secrets/sops.nix similarity index 70% rename from nixosModules/clanCore/secrets/sops.nix rename to nixosModules/core/secrets/sops.nix index 7df0b31d2..cc0507d5d 100644 --- a/nixosModules/clanCore/secrets/sops.nix +++ b/nixosModules/core/secrets/sops.nix @@ -7,24 +7,24 @@ set -x # remove for prod PATH=$PATH:${lib.makeBinPath [ - config.clanCore.clanPkgs.clan-cli + config.clan.core.clanPkgs.clan-cli ]} # initialize secret store - if ! clan secrets machines list | grep -q ${config.clanCore.machineName}; then ( + if ! clan secrets machines list | grep -q ${config.clan.core.machineName}; then ( INITTMP=$(mktemp -d) trap 'rm -rf "$INITTMP"' EXIT ${pkgs.age}/bin/age-keygen -o "$INITTMP/secret" 2> "$INITTMP/public" PUBKEY=$(cat "$INITTMP/public" | sed 's/.*: //') - clan secrets machines add ${config.clanCore.machineName} "$PUBKEY" - tail -1 "$INITTMP/secret" | clan secrets set --machine ${config.clanCore.machineName} ${config.clanCore.machineName}-age.key + clan secrets machines add ${config.clan.core.machineName} "$PUBKEY" + tail -1 "$INITTMP/secret" | clan secrets set --machine ${config.clan.core.machineName} ${config.clan.core.machineName}-age.key ) fi ${lib.foldlAttrs (acc: n: v: '' ${acc} # ${n} # if any of the secrets are missing, we regenerate all connected facts/secrets - (if ! ${lib.concatMapStringsSep " && " (x: "clan secrets get ${config.clanCore.machineName}-${x.name} >/dev/null") (lib.attrValues v.secrets)}; then + (if ! ${lib.concatMapStringsSep " && " (x: "clan secrets get ${config.clan.core.machineName}-${x.name} >/dev/null") (lib.attrValues v.secrets)}; then facts=$(mktemp -d) trap "rm -rf $facts" EXIT @@ -38,24 +38,24 @@ '') (lib.attrValues v.facts)} ${lib.concatMapStrings (secret: '' - cat "$secrets"/${secret.name} | clan secrets set --machine ${config.clanCore.machineName} ${config.clanCore.machineName}-${secret.name} + cat "$secrets"/${secret.name} | clan secrets set --machine ${config.clan.core.machineName} ${config.clan.core.machineName}-${secret.name} '') (lib.attrValues v.secrets)} fi) - '') "" config.clanCore.secrets} + '') "" config.clan.core.secrets} ''; sops.secrets = let encryptedForThisMachine = name: type: let - symlink = config.clanCore.clanDir + "/sops/secrets/${name}/machines/${config.clanCore.machineName}"; + symlink = config.clan.core.clanDir + "/sops/secrets/${name}/machines/${config.clan.core.machineName}"; in # WTF, nix bug, my symlink is in the nixos module detected as a directory also it works in the repl type == "directory" && (builtins.readFileType symlink == "directory" || builtins.readFileType symlink == "symlink"); - secrets = lib.filterAttrs encryptedForThisMachine (builtins.readDir (config.clanCore.clanDir + "/sops/secrets")); + secrets = lib.filterAttrs encryptedForThisMachine (builtins.readDir (config.clan.core.clanDir + "/sops/secrets")); in builtins.mapAttrs (name: _: { - sopsFile = config.clanCore.clanDir + "/sops/secrets/${name}/secret"; + sopsFile = config.clan.core.clanDir + "/sops/secrets/${name}/secret"; format = "binary"; }) secrets; diff --git a/nixosModules/clanCore/zerotier.nix b/nixosModules/core/zerotier.nix similarity index 95% rename from nixosModules/clanCore/zerotier.nix rename to nixosModules/core/zerotier.nix index 452294d95..67b9b6fec 100644 --- a/nixosModules/clanCore/zerotier.nix +++ b/nixosModules/core/zerotier.nix @@ -41,13 +41,13 @@ in } // lib.mkIf cfg.controller.enable { # only the controller needs to have the key in the repo, the other clients can be dynamic # we generate the zerotier code manually for the controller, since it's part of the bootstrap command - clanCore.secrets.zerotier = { + clan.core.secrets.zerotier = { facts."network.id" = { }; secrets."identity.secret" = { }; generator = '' TMPDIR=$(mktemp -d) trap 'rm -rf "$TMPDIR"' EXIT - ${config.clanCore.clanPkgs.clan-cli}/bin/clan zerotier --outpath "$TMPDIR" + ${config.clan.core.clanPkgs.clan-cli}/bin/clan zerotier --outpath "$TMPDIR" cp "$TMPDIR"/network.id "$facts"/network.id cp "$TMPDIR"/identity.secret "$secrets"/identity.secret ''; diff --git a/pkgs/clan-cli/clan_cli/secrets/generate.py b/pkgs/clan-cli/clan_cli/secrets/generate.py index 0b01a8c85..01499db0a 100644 --- a/pkgs/clan-cli/clan_cli/secrets/generate.py +++ b/pkgs/clan-cli/clan_cli/secrets/generate.py @@ -15,7 +15,7 @@ def get_secret_script(machine: str) -> None: "--expr", "let f = builtins.getFlake (toString ./.); in " f"(f.nixosConfigurations.{machine}.extendModules " - "{ modules = [{ clanCore.clanDir = toString ./.; }]; })" + "{ modules = [{ clan.core.clanDir = toString ./.; }]; })" ".config.system.clan.generateSecrets", ], check=True, From ed16ac42b78eabfbf765c30f6d32c09b0a93f941 Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Wed, 30 Aug 2023 15:50:15 +0200 Subject: [PATCH 4/4] UI: Fixed CI Bug --- pkgs/ui/src/components/table/searchBar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/ui/src/components/table/searchBar.tsx b/pkgs/ui/src/components/table/searchBar.tsx index c5ea2611d..8aca96928 100644 --- a/pkgs/ui/src/components/table/searchBar.tsx +++ b/pkgs/ui/src/components/table/searchBar.tsx @@ -48,7 +48,7 @@ export function SearchBar(props: SearchBarProps) { }); setFilteredList(filtered); } - }, [debouncedSearch]); + }, [debouncedSearch, tableData, setFilteredList]); const handleInputChange = (e: React.ChangeEvent) => { if (e.target.value === "") {