diff --git a/README.md b/README.md index 3665265..6166feb 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,12 @@ # `config-manager` `./config-manager` is a module that contains a script to make usage of this flake easier. -To install it first add the module to the nixOS system connfiguration and then -run `nixos-rebuild switch --flake .#`, after that `cm` will be available on `$PATH`. +To install it +1. first add the module to the nixOS system connfiguration +2. set `config-manager.flakePath = ` +3. set `config-manager.system = ` +4. run `nixos-rebuild switch --flake .#` +after that `cm` will be available on `$PATH`. # Secrets Secrets are managed by `agenix` (https://github.com/ryantm/agenix). diff --git a/config-manager/default.nix b/config-manager/default.nix index 8b9aac4..03d977b 100644 --- a/config-manager/default.nix +++ b/config-manager/default.nix @@ -1,11 +1,18 @@ -{ pkgs, lib, config, ... }: +{ inputs, pkgs, lib, config, ... }: let - config-manager = let - flakePath = config.config-manager.flakePath; - nixosConfiguration = config.config-manager.nixosConfiguration; - in + flakePath = config.config-manager.flakePath; + nixosConfiguration = config.config-manager.nixosConfiguration; + system = config.config-manager.system; + + nh = inputs.nh.packages."${system}".default; + + config-manager = if flakePath == "" then throw "'config-manager.flakePath' cannot be empty" + else if nixosConfiguration == "" then + throw "'config-manager.nixosConfiguration' cannot be empty" + else if system == "" then + throw "'config-manager.system' cannot be empty" else pkgs.writeShellScriptBin "cm" '' help() { @@ -25,7 +32,7 @@ EOF } switch() { - nh os switch --hostname ${nixosConfiguration} ${flakePath} + ${nh}/bin/nh os switch --hostname ${nixosConfiguration} ${flakePath} } case $1 in @@ -52,10 +59,19 @@ in default = config.networking.hostName; description = "what nixosConfiguration to use"; }; + + system = lib.mkOption { + type = lib.types.str; + default = ""; + description = "what system the host is (x86_64-linux, aarch64-linux)"; + }; }; }; config = { - environment.systemPackages = [ config-manager ]; + environment.systemPackages = [ + nh + config-manager + ]; }; } diff --git a/flake.nix b/flake.nix index 8b77953..d833a09 100644 --- a/flake.nix +++ b/flake.nix @@ -51,6 +51,7 @@ sombrero = inputs.nixpkgs2211.lib.nixosSystem { system = "aarch64-linux"; + specialArgs = { inherit inputs; }; modules = [ ./hosts/sombrero/configuration.nix inputs.home-manager.nixosModules.home-manager diff --git a/hosts/pinwheel/configuration.nix b/hosts/pinwheel/configuration.nix index 458d8c4..0748b89 100644 --- a/hosts/pinwheel/configuration.nix +++ b/hosts/pinwheel/configuration.nix @@ -66,13 +66,15 @@ environment.systemPackages = with pkgs; [ inputs.agenix.packages."${system}".default - inputs.nh.packages."${system}".default coreutils gnumake bash ]; - config-manager.flakePath = "/home/alex/config"; + config-manager = { + flakePath = "/home/alex/config"; + system=system; + }; mod = { nix-index.enable = true; diff --git a/hosts/sombrero/configuration.nix b/hosts/sombrero/configuration.nix index 18c017c..388e978 100644 --- a/hosts/sombrero/configuration.nix +++ b/hosts/sombrero/configuration.nix @@ -370,7 +370,10 @@ restic ]; - config-manager.flakePath = "/home/alex/config"; + config-manager = { + flakePath = "/home/alex/config"; + system = "aarch64-linux"; + }; # Copy the NixOS configuration file and link it from the resulting system # (/run/current-system/configuration.nix). This is useful in case you