diff --git a/lib/default.nix b/lib/default.nix index ce72aaa..ffcb1b4 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -59,7 +59,10 @@ let # Get paths to directories onlyDirs = lib.filterAttrs (name: type: type == "directory") entries; - dirPaths = lib.mapAttrs (name: _: path + "/${name}") onlyDirs; + dirPaths = lib.mapAttrs (name: type: { + path = path + "/${name}"; + inherit type; + }) onlyDirs; # Get paths to nix files, where the name is the basename of the file without the .nix extension nixPaths = builtins.removeAttrs (lib.mapAttrs' ( @@ -69,7 +72,10 @@ let in { name = if type == "directory" || nixName == null then "__junk" else (builtins.head nixName); - value = path + "/${name}"; + value = { + path = path + "/${name}"; + type = type; + }; } ) entries) [ "__junk" ]; @@ -78,6 +84,8 @@ let in lib.optionalAttrs (builtins.pathExists path) (fn combined); + entriesPath = entries: lib.mapAttrs (name: { path, type }: path); + # Prefixes all the keys of an attrset with the given prefix withPrefix = prefix: @@ -159,7 +167,8 @@ let }; loadHost = - name: path: + name: + { path, type }: if builtins.pathExists (path + "/configuration.nix") then loadNixOS (path + "/configuration.nix") else if builtins.pathExists (path + "/darwin-configuration.nix") then @@ -183,10 +192,10 @@ let ); modules = { - common = importDir (src + "/modules/common") lib.id; - darwin = importDir (src + "/modules/darwin") lib.id; - home = importDir (src + "/modules/home") lib.id; - nixos = importDir (src + "/modules/nixos") lib.id; + common = importDir (src + "/modules/common") entriesPath; + darwin = importDir (src + "/modules/darwin") entriesPath; + home = importDir (src + "/modules/home") entriesPath; + nixos = importDir (src + "/modules/nixos") entriesPath; }; in # FIXME: maybe there are two layers to this. The blueprint, and then the mapping to flake outputs. @@ -214,7 +223,17 @@ let packages = importDir (src + "/pkgs") ( entries: - eachSystem (args: lib.mapAttrs (pname: path: import path (args // { inherit pname; })) entries) + eachSystem ( + { pkgs, ... }@args: + lib.mapAttrs ( + pname: + { path, type }: + if type != "directory" || !builtins.pathExists (path + "/default.nix") then + pkgs.callPackage "${toString path}/package.nix" { } + else + import path (args // { inherit pname; }) + ) entries + ) ); darwinConfigurations = hostsByCategory.darwinConfigurations or { }; @@ -228,11 +247,15 @@ let templates = importDir (src + "/templates") ( entries: - lib.mapAttrs (name: path: { - path = path; - # FIXME: how can we add something more meaningful? - description = name; - }) entries + lib.mapAttrs ( + name: + { path, type }: + { + path = path; + # FIXME: how can we add something more meaningful? + description = name; + } + ) entries ); checks = eachSystem ( diff --git a/pkgs/bp/default.nix b/pkgs/bp/package.nix similarity index 59% rename from pkgs/bp/default.nix rename to pkgs/bp/package.nix index 0098296..3b9f5ae 100644 --- a/pkgs/bp/default.nix +++ b/pkgs/bp/package.nix @@ -1,12 +1,11 @@ { - pname, - pkgs, - flake, - ... + nixos-rebuild, + runCommand, + writeShellApplication, }: let - pb = pkgs.writeShellApplication { - name = pname; + pb = writeShellApplication { + name = "bp"; runtimeInputs = [ ]; @@ -19,10 +18,10 @@ let shift # Allow running the command as a user export SUDO_USER=1 - echo ${pkgs.nixos-rebuild}/bin/nixos-rebuild --flake ${flake} "$@" + echo ${nixos-rebuild}/bin/nixos-rebuild --flake . switch "$@" ;; *) - echo "Usage: ${pname} [switch]" + echo "Usage: bp [switch]" ;; esac ''; @@ -30,7 +29,7 @@ let meta = { description = "ignore me, this is not ready"; - tests.does-it-run = pkgs.runCommand "${pname}-does-it-run" { } '' + tests.does-it-run = runCommand "bp-does-it-run" { } '' ${pb}/bin/bp --help > $out ''; };