2022-02-19 23:34:41 +00:00
|
|
|
{ pkgs, ... }:
|
|
|
|
let
|
2023-08-21 23:38:42 +01:00
|
|
|
homeFlake = "$HOME/.config/home-manager/flake.nix";
|
2022-02-22 01:30:27 +00:00
|
|
|
devKey = ".keys/dev.key";
|
2022-02-19 23:34:41 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
commands = [
|
|
|
|
{
|
|
|
|
name = "repl";
|
|
|
|
category = "utilities";
|
|
|
|
help = "Open a `nix repl` with this flake";
|
2023-10-31 14:38:51 +00:00
|
|
|
command = "nix repl .#";
|
2022-02-19 23:34:41 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "home-link";
|
|
|
|
category = "utilities";
|
|
|
|
help = "Install link to flake.nix for home-manager to use";
|
|
|
|
command =
|
|
|
|
''
|
|
|
|
[ -e "${homeFlake}" ] && echo "${homeFlake} already exists" && exit 1
|
|
|
|
|
|
|
|
mkdir -p "$(dirname "${homeFlake}")"
|
2024-01-15 14:59:01 +00:00
|
|
|
ln -sf "$(pwd)/flake.nix" "${homeFlake}"
|
2022-02-19 23:34:41 +00:00
|
|
|
echo "Installed link to $(pwd)/flake.nix at ${homeFlake}"
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "home-unlink";
|
|
|
|
category = "utilities";
|
|
|
|
help = "Remove home-manager flake.nix link";
|
|
|
|
command = "rm -f ${homeFlake}";
|
|
|
|
}
|
2022-02-22 00:59:57 +00:00
|
|
|
{
|
2023-01-08 18:50:52 +00:00
|
|
|
name = "ragenix";
|
2022-02-22 00:59:57 +00:00
|
|
|
category = "utilities";
|
2023-01-08 18:50:52 +00:00
|
|
|
help = "age-encrypted secrets for NixOS";
|
|
|
|
command = ''exec ${pkgs.ragenix}/bin/ragenix --identity "$PRJ_ROOT/.keys/dev.key" "$@"'';
|
2022-02-22 00:59:57 +00:00
|
|
|
}
|
2022-05-12 21:06:46 +01:00
|
|
|
{
|
|
|
|
name = "qemu-genmac";
|
|
|
|
category = "utilities";
|
|
|
|
help = "Generate MAC address suitable for QEMU";
|
2022-05-16 00:05:02 +01:00
|
|
|
command = ''printf "52:54:00:%02x:%02x:%02x\n" $((RANDOM%256)) $((RANDOM%256)) $((RANDOM%256))'';
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "ssh-get-ed25519";
|
|
|
|
category = "utilities";
|
|
|
|
help = "Print the ed25519 pubkey for a host";
|
|
|
|
command = "${pkgs.openssh}/bin/ssh-keyscan -t ed25519 \"$1\" 2> /dev/null | awk '{ print $2 \" \" $3 }'";
|
2022-05-12 21:06:46 +01:00
|
|
|
}
|
2023-12-13 00:40:36 +00:00
|
|
|
{
|
|
|
|
name = "json2nix";
|
|
|
|
category = "utilities";
|
|
|
|
help = "Convert JSON to formatted Nix";
|
|
|
|
command = "nix eval --impure --expr 'builtins.fromJSON (builtins.readFile /dev/stdin)' | ${pkgs.nixfmt}/bin/nixfmt";
|
|
|
|
}
|
2022-02-19 23:34:41 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
name = "fmt";
|
|
|
|
category = "tasks";
|
|
|
|
help = pkgs.nixpkgs-fmt.meta.description;
|
|
|
|
command = ''exec "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt" "$@"'';
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "home-switch";
|
|
|
|
category = "tasks";
|
|
|
|
help = "Run `home-manager switch`";
|
|
|
|
command = ''home-manager switch --flake . "$@"'';
|
|
|
|
}
|
2022-02-19 23:57:06 +00:00
|
|
|
{
|
|
|
|
name = "build-system";
|
|
|
|
category = "tasks";
|
|
|
|
help = "Build NixOS configuration";
|
|
|
|
command = ''nix build "''${@:2}" ".#nixosConfigurations.\"$1\".config.system.build.toplevel"'';
|
|
|
|
}
|
2022-09-09 12:15:25 +01:00
|
|
|
{
|
|
|
|
name = "build-n-switch";
|
|
|
|
category = "tasks";
|
2022-09-09 14:08:37 +01:00
|
|
|
help = "Shortcut to nixos-rebuild for this flake";
|
|
|
|
command = ''doas nixos-rebuild --flake . "$@"'';
|
2022-09-09 12:15:25 +01:00
|
|
|
}
|
2022-02-19 23:57:06 +00:00
|
|
|
{
|
|
|
|
name = "run-vm";
|
|
|
|
category = "tasks";
|
|
|
|
help = "Run NixOS configuration as a VM";
|
|
|
|
command =
|
|
|
|
''
|
|
|
|
cd "$PRJ_ROOT"
|
2022-02-22 01:30:27 +00:00
|
|
|
tmp="$(mktemp -d nix-vm.XXXXXXXXXX --tmpdir)"
|
|
|
|
install -Dm0400 "${devKey}" "$tmp/xchg/dev.key"
|
|
|
|
TMPDIR="$tmp" USE_TMPDIR=1 nix run ".#nixosConfigurations.\"$1\".config.my.buildAs.devVM"
|
2022-02-19 23:57:06 +00:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "build-iso";
|
|
|
|
category = "tasks";
|
|
|
|
help = "Build NixOS configuration into an ISO";
|
2023-11-16 21:42:30 +00:00
|
|
|
command = ''nix build "''${@:2}" ".#nixfiles.config.nixos.systems.\"$1\".configuration.config.my.buildAs.iso"'';
|
2022-02-19 23:57:06 +00:00
|
|
|
}
|
2023-12-17 14:42:55 +00:00
|
|
|
{
|
|
|
|
name = "build-kexec";
|
|
|
|
category = "tasks";
|
|
|
|
help = "Build NixOS configuration as kexec tree";
|
|
|
|
command = ''nix build "''${@:2}" ".#nixfiles.config.nixos.systems.\"$1\".configuration.config.my.buildAs.kexecTree"'';
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "build-netboot";
|
|
|
|
category = "tasks";
|
|
|
|
help = "Build NixOS configuration as netboot archive";
|
|
|
|
command = ''nix build "''${@:2}" ".#nixfiles.config.nixos.systems.\"$1\".configuration.config.my.buildAs.netbootArchive"'';
|
|
|
|
}
|
2022-02-19 23:57:06 +00:00
|
|
|
{
|
|
|
|
name = "build-home";
|
|
|
|
category = "tasks";
|
|
|
|
help = "Build home-manager configuration";
|
|
|
|
command = ''nix build "''${@:2}" ".#homeConfigurations.\"$1\".activationPackage"'';
|
|
|
|
}
|
2022-05-28 18:38:03 +01:00
|
|
|
{
|
|
|
|
name = "update-inputs";
|
|
|
|
category = "tasks";
|
|
|
|
help = "Update flake inputs";
|
|
|
|
command = ''
|
|
|
|
args=()
|
|
|
|
for f in "$@"; do
|
|
|
|
args+=(--update-input "$f")
|
|
|
|
done
|
|
|
|
nix flake lock "''${args[@]}"
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "update-nixpkgs";
|
|
|
|
category = "tasks";
|
|
|
|
help = "Update nixpkgs flake inputs";
|
|
|
|
command = ''update-inputs nixpkgs-{unstable,stable,mine,mine-stable}'';
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "update-home-manager";
|
|
|
|
category = "tasks";
|
|
|
|
help = "Update home-manager flake inputs";
|
|
|
|
command = ''update-inputs home-manager-{unstable,stable}'';
|
|
|
|
}
|
2023-12-05 16:58:20 +00:00
|
|
|
{
|
|
|
|
name = "update-installer";
|
|
|
|
category = "tasks";
|
|
|
|
help = "Update installer tag (to trigger new release)";
|
|
|
|
command = ''git tag -f installer && git push -f origin installer'';
|
|
|
|
}
|
2022-02-19 23:34:41 +00:00
|
|
|
];
|
|
|
|
}
|