Add config-manager
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
|
# `config-manager`
|
||||||
|
`./config-manager` is a module that contains a script to make usage
|
||||||
|
of this flake easier.
|
||||||
|
|
||||||
# Secrets
|
# Secrets
|
||||||
Secrets are managed by `agenix` (https://github.com/ryantm/agenix).
|
Secrets are managed by `agenix` (https://github.com/ryantm/agenix).
|
||||||
|
|
||||||
## Creating new secrets
|
## Creating new secrets
|
||||||
1. Update `secrets/secrets.nix` with the new secret.
|
1. Update `secrets/secrets.nix` with the new secret.
|
||||||
|
|
||||||
|
|||||||
62
config-manager/default.nix
Normal file
62
config-manager/default.nix
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
{ pkgs, lib, config, ... }:
|
||||||
|
let
|
||||||
|
config-manager = let
|
||||||
|
flakePath = config.config-manager.flakePath;
|
||||||
|
nixosConfiguration = config.config-manager.nixosConfiguration;
|
||||||
|
in
|
||||||
|
if flakePath == "" then
|
||||||
|
throw "'config-manager.flakePath' cannot be empty"
|
||||||
|
else
|
||||||
|
pkgs.writeShellScriptBin "cm" ''
|
||||||
|
help() {
|
||||||
|
cat << EOF
|
||||||
|
Usage:
|
||||||
|
cm [flag]
|
||||||
|
|
||||||
|
Flags:
|
||||||
|
--update updates the flake
|
||||||
|
--switch rebuilds + switches configuration
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
update() {
|
||||||
|
echo -e "\033[0;31mUPDATING FLAKE"
|
||||||
|
sudo nix flake update
|
||||||
|
}
|
||||||
|
|
||||||
|
switch() {
|
||||||
|
echo -e "\033[0;31mREBUILDING + SWITCHING CONFIG"
|
||||||
|
sudo nixos-rebuild switch --flake ${flakePath}#${nixosConfiguration}
|
||||||
|
}
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
--update)
|
||||||
|
update ;;
|
||||||
|
--switch)
|
||||||
|
switch ;;
|
||||||
|
--help | *)
|
||||||
|
help ;;
|
||||||
|
esac
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
config-manager = {
|
||||||
|
flakePath = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "";
|
||||||
|
description = "path to this flake";
|
||||||
|
};
|
||||||
|
|
||||||
|
nixosConfiguration = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = config.networking.hostName;
|
||||||
|
description = "what nixosConfiguration to use";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
environment.systemPackages = [ config-manager ];
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user