diff --git a/flake.nix b/flake.nix index 32d5418..5f97bee 100644 --- a/flake.nix +++ b/flake.nix @@ -28,10 +28,6 @@ url = "github:oxalica/nil"; inputs.nixpkgs.follows = "nixpkgs"; }; - # wrapper-manager = { - # url = "github:viperML/wrapper-manager"; - # inputs.nixpkgs.follows = "nixpkgs"; - # }; #nix.url = "github:DeterminateSystems/nix-src"; }; @@ -40,7 +36,8 @@ inherit (nixpkgs.lib) attrsToList const groupBy listToAttrs mapAttrs; #nix.enable = false; - lib = nixpkgs.lib // nix-darwin.lib; + lib' = nixpkgs.lib.extend (_: _: nix-darwin.lib); + lib = lib'.extend <| import ./lib inputs; targetHost = readDir ./hosts |> mapAttrs (name: const <| import ./hosts/${name} lib inputs self) diff --git a/hosts/thegeneralist-central-mbp/default.nix b/hosts/thegeneralist-central-mbp/default.nix index 1d90efc..3f28ae9 100644 --- a/hosts/thegeneralist-central-mbp/default.nix +++ b/hosts/thegeneralist-central-mbp/default.nix @@ -1,30 +1 @@ -lib: inputs: self: lib.darwinSystem { - specialArgs = inputs // { inherit inputs; inherit self; }; - modules = [ - # Extensions: nixosModules, darwinModules, overlays - ({ pkgs, lib, inputs, ... }: let - inherit (lib) attrValues hasAttrByPath getAttrFromPath filter; - - collect = packagePath: (attrValues inputs) - |> filter (hasAttrByPath packagePath) - |> map (getAttrFromPath packagePath); - - modules = collect [ "darwinModules" "default" ]; - extensions = { - nixpkgs.overlays = collect [ "overlays" "default" ]; - imports = modules; - }; - in extensions) - - ./configuration.nix - - # Modules - ({ pkgs, ... }: let - inherit (lib) filter hasSuffix; - commonModules = lib.filesystem.listFilesRecursive ../../modules/common |> filter (hasSuffix ".nix"); - darwinModules = lib.filesystem.listFilesRecursive ../../modules/darwin |> filter (hasSuffix ".nix"); - in { - imports = commonModules ++ darwinModules; - }) - ]; -} +lib: inputs: self: lib.system "darwin" ./configuration.nix diff --git a/hosts/thegeneralist-central/default.nix b/hosts/thegeneralist-central/default.nix index 2fa7865..c37f12f 100644 --- a/hosts/thegeneralist-central/default.nix +++ b/hosts/thegeneralist-central/default.nix @@ -1,30 +1 @@ -lib: inputs: self: lib.nixosSystem { - specialArgs = inputs // { inherit inputs; inherit self; }; - modules = [ - # Extensions: nixosModules, darwinModules, overlays - ({ pkgs, lib, inputs, ... }: let - inherit (lib) attrValues hasAttrByPath getAttrFromPath filter; - - collect = packagePath: (attrValues inputs) - |> filter (hasAttrByPath packagePath) - |> map (getAttrFromPath packagePath); - - modules = collect [ "nixosModules" "default" ]; - extensions = { - nixpkgs.overlays = collect [ "overlays" "default" ]; - imports = modules; - }; - in extensions) - - ./configuration.nix - - # Modules - ({ pkgs, ... }: let - inherit (lib) filter hasSuffix; - commonModules = lib.filesystem.listFilesRecursive ../../modules/common |> filter (hasSuffix ".nix"); - linuxModules = lib.filesystem.listFilesRecursive ../../modules/linux |> filter (hasSuffix ".nix"); - in { - imports = commonModules ++ linuxModules; - }) - ]; -} +lib: inputs: self: lib.system "linux" ./configuration.nix diff --git a/hosts/thegeneralist-mbp/default.nix b/hosts/thegeneralist-mbp/default.nix index 1d90efc..3f28ae9 100644 --- a/hosts/thegeneralist-mbp/default.nix +++ b/hosts/thegeneralist-mbp/default.nix @@ -1,30 +1 @@ -lib: inputs: self: lib.darwinSystem { - specialArgs = inputs // { inherit inputs; inherit self; }; - modules = [ - # Extensions: nixosModules, darwinModules, overlays - ({ pkgs, lib, inputs, ... }: let - inherit (lib) attrValues hasAttrByPath getAttrFromPath filter; - - collect = packagePath: (attrValues inputs) - |> filter (hasAttrByPath packagePath) - |> map (getAttrFromPath packagePath); - - modules = collect [ "darwinModules" "default" ]; - extensions = { - nixpkgs.overlays = collect [ "overlays" "default" ]; - imports = modules; - }; - in extensions) - - ./configuration.nix - - # Modules - ({ pkgs, ... }: let - inherit (lib) filter hasSuffix; - commonModules = lib.filesystem.listFilesRecursive ../../modules/common |> filter (hasSuffix ".nix"); - darwinModules = lib.filesystem.listFilesRecursive ../../modules/darwin |> filter (hasSuffix ".nix"); - in { - imports = commonModules ++ darwinModules; - }) - ]; -} +lib: inputs: self: lib.system "darwin" ./configuration.nix diff --git a/hosts/thegeneralist/default.nix b/hosts/thegeneralist/default.nix index 2fa7865..c37f12f 100644 --- a/hosts/thegeneralist/default.nix +++ b/hosts/thegeneralist/default.nix @@ -1,30 +1 @@ -lib: inputs: self: lib.nixosSystem { - specialArgs = inputs // { inherit inputs; inherit self; }; - modules = [ - # Extensions: nixosModules, darwinModules, overlays - ({ pkgs, lib, inputs, ... }: let - inherit (lib) attrValues hasAttrByPath getAttrFromPath filter; - - collect = packagePath: (attrValues inputs) - |> filter (hasAttrByPath packagePath) - |> map (getAttrFromPath packagePath); - - modules = collect [ "nixosModules" "default" ]; - extensions = { - nixpkgs.overlays = collect [ "overlays" "default" ]; - imports = modules; - }; - in extensions) - - ./configuration.nix - - # Modules - ({ pkgs, ... }: let - inherit (lib) filter hasSuffix; - commonModules = lib.filesystem.listFilesRecursive ../../modules/common |> filter (hasSuffix ".nix"); - linuxModules = lib.filesystem.listFilesRecursive ../../modules/linux |> filter (hasSuffix ".nix"); - in { - imports = commonModules ++ linuxModules; - }) - ]; -} +lib: inputs: self: lib.system "linux" ./configuration.nix diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 0000000..c7e9336 --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,5 @@ +inputs: self: super: +let + system = import ./system.nix inputs self super; +in +system diff --git a/lib/system.nix b/lib/system.nix new file mode 100644 index 0000000..9bf55ae --- /dev/null +++ b/lib/system.nix @@ -0,0 +1,66 @@ +inputs: self: super: +let + inherit (self) + hasSuffix + filesystem + attrValues + filter + getAttrFromPath + hasAttrByPath + ; + + collectModules = path: filesystem.listFilesRecursive path |> filter (hasSuffix ".nix"); + + collectInputModules = + packagePath: + (attrValues inputs) |> filter (hasAttrByPath packagePath) |> map (getAttrFromPath packagePath); + + specialArgs = inputs // { + inherit inputs; + inherit self; + }; + + # All modules + modulesCommon = collectModules ../modules/common; + modulesLinux = collectModules ../modules/linux; + modulesDarwin = collectModules ../modules/darwin; + + inputModulesNixos = collectInputModules [ + "nixosModules" + "default" + ]; + inputModulesDarwin = collectInputModules [ + "darwinModules" + "default" + ]; + + # Overlays + overlays = collectInputModules [ + "overlays" + "default" + ]; + + overlayModules = { + nixpkgs.overlays = overlays; + }; +in +{ + system = + os: configFile: + if os == "darwin" then + super.darwinSystem + else + super.nixosSystem { + inherit specialArgs; + + modules = + [ + overlayModules + configFile + ] + ++ modulesCommon + ++ ( + if os == "darwin" then modulesDarwin ++ inputModulesDarwin else modulesLinux ++ inputModulesNixos + ); + }; +}