config-manager: Move installation of nh to module

And add `system` option that is required to pick the correct package
from `nh`
This commit is contained in:
Alexander Heldt
2023-10-22 14:03:02 +02:00
parent c2b051ad31
commit 11cb33039b
5 changed files with 38 additions and 12 deletions

View File

@@ -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 .#<configuration>`, 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 = <path to this flake>`
3. set `config-manager.system = <system type for the machine>`
4. run `nixos-rebuild switch --flake .#<configuration>`
after that `cm` will be available on `$PATH`.
# Secrets
Secrets are managed by `agenix` (https://github.com/ryantm/agenix).

View File

@@ -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
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
];
};
}

View File

@@ -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

View File

@@ -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;

View File

@@ -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