try out styx as a main repo

This commit is contained in:
Daylin Morgan 2024-01-24 14:12:52 -06:00
parent d8972aae6c
commit 93f13d2049
Signed by: daylin
GPG Key ID: C1E52E7DD81DF79F
4 changed files with 32 additions and 16 deletions

View File

@ -23,8 +23,10 @@
...
}: let
lib = import ./lib {inherit inputs nixpkgs;};
inherit (lib) findModules mapHosts shToPkg;
in {
nixosModules = builtins.listToAttrs (lib.findModules ./modules);
nixosConfigurations = lib.mapHosts ./hosts;
nixosModules = findModules ./modules;
nixosConfigurations = mapHosts ./hosts;
packages = shToPkg ./styx;
};
}

View File

@ -3,10 +3,25 @@
nixpkgs,
...
}: let
inherit (builtins) concatLists attrValues mapAttrs elemAt match readDir filter;
inherit (nixpkgs.lib) hasSuffix nixosSystem;
inherit (builtins) concatLists attrValues mapAttrs elemAt match readDir filter listToAttrs baseNameOf readFile;
inherit (nixpkgs.lib) hasSuffix nixosSystem genAttrs;
inherit (nixpkgs.lib.filesystem) listFilesRecursive;
# https://xeiaso.net/blog/nix-flakes-1-2022-02-21/
supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
forAllSystems = genAttrs supportedSystems;
nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system;});
in rec {
shToPkg = path:
forAllSystems (
system: let
name = baseNameOf path;
pkgs = nixpkgsFor.${system};
in {
${name} = pkgs.writeScriptBin name (readFile path);
}
);
isNixFile = path: hasSuffix ".nix" path;
mkSystem = hostname:
@ -14,7 +29,7 @@ in rec {
system = "x86_64-linux";
modules =
[../modules/roles/common.nix]
++ builtins.filter isNixFile (listFilesRecursive (../. + "/hosts/${hostname}"));
++ filter isNixFile (listFilesRecursive (../. + "/hosts/${hostname}"));
specialArgs = {inherit inputs;};
};
@ -23,8 +38,9 @@ in rec {
(name: _: mkSystem name)
(readDir dir);
findModules = modulesPath: listToAttrs (findModulesList modulesPath);
# https://github.com/balsoft/nixos-config/blob/73cc2c3a8bb62a9c3980a16ae70b2e97af6e1abd/flake.nix#L109-L120
findModules = dir:
findModulesList = dir:
concatLists (attrValues (mapAttrs
(name: type:
if type == "regular"
@ -43,5 +59,5 @@ in rec {
value = dir + "/${name}";
}
]
else findModules (dir + "/${name}")) (readDir dir)));
else findModulesList (dir + "/${name}")) (readDir dir)));
}

View File

@ -1,5 +0,0 @@
{pkgs, ...}: {
environment.systemPackages = with pkgs; [
(writeScriptBin "styx" (builtins.readFile ./styx))
];
}

View File

@ -5,7 +5,7 @@ set -e
# rewrite as python script?
HOSTNAME=${HOSTNAME:-$(hostname)}
FLAKE_PATH=${FLAKE_PATH-:$HOME/nixcfg}
FLAKE_PATH=${FLAKE_PATH:-$HOME/nixcfg}
DIM="$(tput dim)"
BOLD="$(tput bold)"
@ -30,7 +30,6 @@ styx <cmd> [-h]
${DIM}sister moon to nix on pluto
sister software to nix in this repo${RESET}
pass additional args with -- --key value
${BOLD}commands${RESET}:
EOF
printf "${GREEN}%8s${RESET} | ${YELLOW}%s${RESET}\n" \
@ -38,7 +37,8 @@ EOF
build "build and monitor with nom" \
boot "evaluate flake for next boot" \
switch "perform nixos rebuild" \
store "run some store cleanup"
store "run some store cleanup" \
cache "nix build and push to daylin.cachix.org"
exit
}
@ -99,6 +99,10 @@ while [[ $# -gt 0 ]]; do
;;
--help)
help
;;
--)
shift
break
;;
-*,--*)
error "unknown flag: ${BOLD}$1${RESET}"
@ -116,5 +120,4 @@ if [[ $# -gt 0 ]]; then
fi
$cmd "$@"