From 93f13d20494e6db8705db3d826e297bac00b9849 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Wed, 24 Jan 2024 14:12:52 -0600 Subject: [PATCH] try out styx as a main repo --- flake.nix | 6 ++++-- lib/default.nix | 26 +++++++++++++++++++++----- modules/styx/default.nix | 5 ----- modules/styx/styx => styx | 11 +++++++---- 4 files changed, 32 insertions(+), 16 deletions(-) delete mode 100644 modules/styx/default.nix rename modules/styx/styx => styx (92%) diff --git a/flake.nix b/flake.nix index eb6ed3d..67e4c1f 100644 --- a/flake.nix +++ b/flake.nix @@ -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; }; } diff --git a/lib/default.nix b/lib/default.nix index 84ed405..f794bec 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -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))); } diff --git a/modules/styx/default.nix b/modules/styx/default.nix deleted file mode 100644 index a79d803..0000000 --- a/modules/styx/default.nix +++ /dev/null @@ -1,5 +0,0 @@ -{pkgs, ...}: { - environment.systemPackages = with pkgs; [ - (writeScriptBin "styx" (builtins.readFile ./styx)) - ]; -} diff --git a/modules/styx/styx b/styx similarity index 92% rename from modules/styx/styx rename to styx index 849fcb8..564b028 100755 --- a/modules/styx/styx +++ b/styx @@ -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 [-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 "$@"