summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/README.md8
-rw-r--r--lib/builders.nix181
-rw-r--r--lib/default.nix14
-rw-r--r--lib/lib.nix20
-rw-r--r--modules/default.nix1
-rw-r--r--modules/flake/default.nix12
-rw-r--r--modules/flake/map-configs.nix191
-rw-r--r--systems/darwin.nix14
-rw-r--r--systems/nixos.nix24
-rw-r--r--users/default.nix17
10 files changed, 227 insertions, 255 deletions
diff --git a/lib/README.md b/lib/README.md
index bde1e94..97814c5 100644
--- a/lib/README.md
+++ b/lib/README.md
@@ -1,13 +1,5 @@
# ./lib/
-## lib.nix
-
-Top-level declaration of my functions
-
-## builders.nix
-
-Wrappers around configurations builders such as `nixosSystem` and `darwinSystem`
-
## nginx.nix
Small helpers to avoid boilerplate in the `services.nginx` module
diff --git a/lib/builders.nix b/lib/builders.nix
deleted file mode 100644
index 34c8cb9..0000000
--- a/lib/builders.nix
+++ /dev/null
@@ -1,181 +0,0 @@
-{
- lib,
- inputs,
- self,
-}:
-let
- /**
- Wrap the `args` applied to `builder` with the result of `apply`
-
- # Type
-
- ```
- wrapBuilderWith :: (AttrSet -> AttrSet) -> (AttrSet -> AttrSet) -> AttrSet -> AttrSet
- ```
- */
- wrapBuilderWith =
- apply: builder: args:
- builder (apply args);
-
- /**
- Wrap the `args` applied to `builder` with the result of `apply`
-
- # Type
-
- ```
- wrapBuilder :: String -> (AttrSet -> AttrSet) -> AttrSet -> AttrSet
- ```
- */
- wrapBuilder =
- type:
- wrapBuilderWith (
- {
- modules ? [ ],
- specialArgs ? { },
- ...
- }@args:
- args
- // {
- modules = modules ++ lib.attrValues (self."${type}Modules" or { });
-
- specialArgs = specialArgs // {
- inherit inputs;
- };
- }
- );
-
- /**
- Wrap the `args` to the NixOS `builder` function with nice defaults
-
- # Type
-
- ```
- wrapNixOS :: (AttrSet -> AttrSet) -> AttrSet -> AttrSet
- ```
- */
- wrapNixOS = builder: args: wrapBuilder "nixos" builder args;
-
- /**
- Wrap the `args` to the nix-darwin `builder` function with nice defaults
-
- # Type
-
- ```
- wrapDarwin :: (AttrSet -> AttrSet) -> AttrSet -> AttrSet
- ```
- */
- wrapDarwin = builder: args: wrapBuilder "darwin" builder args;
-
- /**
- Wrap the `args` to the home-manager `builder` function with nice defaults
-
- # Type
-
- ```
- wrapUser :: (AttrSet -> AttrSet) -> AttrSet -> AttrSet
- ```
- */
- wrapUser =
- builder: args:
- wrapBuilderWith (
- {
- modules ? [ ],
- extraSpecialArgs ? { },
- ...
- }@args:
- args
- // {
- modules = modules ++ lib.attrValues (self.homeManagerModules or { });
-
- extraSpecialArgs = extraSpecialArgs // {
- inherit inputs;
- };
- }
- ) builder args;
-in
-{
-
- /**
- Wrap the `args` to `nixpkgs.lib.nixosSystem` function with nice defaults
-
- # Example
-
- ```
- nixosSystem { module = [ ./configuration.nix ]; }
- ```
-
- # Type
-
- ```
- nixosSystem :: AttrSet -> AttrSet
- ```
-
- # Arguments
-
- - [args] Base arguments to `nixpkgs.lib.nixosSystem`
- */
- nixosSystem = wrapNixOS inputs.nixpkgs.lib.nixosSystem;
-
- /**
- Wrap the `args` to `nixpkgs-stable.lib.nixosSystem` with nice defaults
-
- # Example
-
- ```
- nixosSystemStable { module = [ ./configuration.nix ]; }
- ```
-
- # Type
-
- ```
- nixosSystemStable :: AttrSet -> AttrSet
- ```
-
- # Arguments
-
- - [args] Base arguments to `nixpkgs.lib.nixosSystem`
- */
- nixosSystemStable = wrapNixOS inputs.nixpkgs-stable.lib.nixosSystem;
-
- /**
- Wrap the `args` to `nix-darwin.lib.darwinSystem` with nice defaults
-
- # Example
-
- ```
- darwinSystem { module = [ ./configuration.nix ]; }
- ```
-
- # Type
-
- ```
- darwinSystem :: AttrSet -> AttrSet
- ```
-
- # Arguments
-
- - [args] Base arguments to `nix-darwin.lib.darwinSystem`
- */
- darwinSystem = wrapDarwin inputs.nix-darwin.lib.darwinSystem;
-
- /**
- Wrap the `args` to `home-manager.lib.homeManagerConfiguration` with nice defaults
-
- # Example
-
- ```
- homeManagerConfiguration { module = [ ./configuration.nix ]; }
- ```
-
- # Type
-
- ```
- homeManagerConfiguration :: AttrSet -> AttrSet
- ```
-
- # Arguments
-
- - [args] Base arguments to `home-manager.lib.homeManagerConfiguration`
- */
- homeManagerConfiguration = wrapUser inputs.home-manager.lib.homeManagerConfiguration;
-}
diff --git a/lib/default.nix b/lib/default.nix
index 7a0cd74..df8d9fb 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -1,17 +1,9 @@
{
lib,
- self,
- inputs,
...
}:
{
- flake.lib =
- (lib.extend (
- final: _: {
- my = import ./lib.nix {
- inherit self inputs;
- lib = final;
- };
- }
- )).my;
+ flake.lib = {
+ nginx = import ./nginx.nix lib;
+ };
}
diff --git a/lib/lib.nix b/lib/lib.nix
deleted file mode 100644
index 54d6712..0000000
--- a/lib/lib.nix
+++ /dev/null
@@ -1,20 +0,0 @@
-{
- lib,
- inputs,
- self,
-}:
-let
- builders = import ./builders.nix { inherit lib inputs self; };
-in
-{
- inherit builders;
-
- inherit (builders)
- nixosSystem
- nixosSystemStable
- darwinSystem
- homeManagerConfiguration
- ;
-
- nginx = import ./nginx.nix lib;
-}
diff --git a/modules/default.nix b/modules/default.nix
index c599041..a91a36b 100644
--- a/modules/default.nix
+++ b/modules/default.nix
@@ -3,5 +3,6 @@
./darwin
./home
./nixos
+ ./flake
];
}
diff --git a/modules/flake/default.nix b/modules/flake/default.nix
new file mode 100644
index 0000000..d06026d
--- /dev/null
+++ b/modules/flake/default.nix
@@ -0,0 +1,12 @@
+let
+ flakeModules = {
+ map-configs = ./map-configs.nix;
+ };
+in
+{
+ imports = [ flakeModules.map-configs ];
+
+ flake = {
+ inherit flakeModules;
+ };
+}
diff --git a/modules/flake/map-configs.nix b/modules/flake/map-configs.nix
new file mode 100644
index 0000000..e7733f3
--- /dev/null
+++ b/modules/flake/map-configs.nix
@@ -0,0 +1,191 @@
+{
+ config,
+ lib,
+ withSystem,
+ inputs,
+ self,
+ ...
+}:
+let
+ nixosSystem =
+ {
+ nixpkgs,
+ modules,
+ specialArgs,
+ ...
+ }@args:
+ nixpkgs.lib.nixosSystem (
+ lib.removeAttrs args [ "nixpkgs" ]
+ // {
+ modules = modules ++ builtins.attrValues (self.nixosModules or [ ]);
+ specialArgs = specialArgs // {
+ inherit inputs;
+ };
+ }
+ );
+
+ darwinSystem =
+ {
+ nix-darwin,
+ modules,
+ specialArgs,
+ ...
+ }@args:
+ nix-darwin.lib.darwinSystem (
+ lib.removeAttrs args [ "nix-darwin" ]
+ // {
+ modules = modules ++ builtins.attrValues (self.darwinModules or { });
+ specialArgs = specialArgs // {
+ inherit inputs;
+ };
+ }
+ );
+
+ homeManagerConfiguration =
+ {
+ modules,
+ extraSpecialArgs,
+ ...
+ }@args:
+ inputs.home-manager.lib.homeManagerConfiguration (
+ args
+ // {
+ modules = modules ++ builtins.attrValues (self.homeModules or self.homeManagerModules or { });
+ extraSpecialArgs = extraSpecialArgs // {
+ inherit inputs;
+ };
+ }
+ );
+
+ modulesOption = lib.mkOption {
+ type = lib.types.listOf lib.types.unspecified;
+ default = [ ];
+ description = ''
+ List of modules to use in the configuration
+ '';
+ };
+
+ specialArgsOption = lib.mkOption {
+ type = lib.types.lazyAttrsOf lib.types.raw;
+ default = { };
+ description = ''
+ Extra arguments to pass to the configuration
+ '';
+ };
+
+ freeformType = lib.types.attrsOf lib.types.raw;
+
+ nixosConfigurationSubmodule = {
+ inherit freeformType;
+
+ options = {
+ nixpkgs = lib.mkOption {
+ type = lib.types.lazyAttrsOf lib.types.raw;
+ default = inputs.nixpkgs or (throw "Could not find flake input `nixpkgs`");
+ description = ''
+ Instance of nixpkgs to use `lib.nixosSystem` from
+ '';
+ example = lib.literalExpression ''
+ inputs.nixpkgs-stable
+ '';
+ };
+
+ modules = modulesOption;
+ specialArgs = specialArgsOption;
+ };
+ };
+
+ homeConfigurationSubmodule = {
+ inherit freeformType;
+
+ options = {
+ pkgs = lib.mkOption {
+ type = lib.types.lazyAttrsOf lib.types.raw;
+ default = withSystem "x86_64-linux" ({ pkgs, ... }: pkgs);
+ description = ''
+ Instance of nixpkgs to use with the configuration
+ '';
+ example = lib.literalExpression ''
+ inputs.nixpkgs.legacyPackages.aarch64-darwin
+ '';
+ };
+
+ modules = modulesOption;
+ extraSpecialArgs = specialArgsOption;
+ };
+ };
+
+ darwinConfigurationSubmodule = {
+ inherit freeformType;
+
+ options = {
+ nix-darwin = lib.mkOption {
+ type = lib.types.lazyAttrsOf lib.types.raw;
+ default =
+ inputs.nix-darwin or inputs.darwin
+ or (throw "Could not find flake input `nixpkgs` or `nix-darwin`");
+ description = ''
+ Instance of nix-darwin to use `lib.nix-darwin` from
+ '';
+ };
+
+ modules = modulesOption;
+ specialArgs = specialArgsOption;
+ };
+ };
+in
+
+{
+ options = {
+ nixosConfigurations = lib.mkOption {
+ type = lib.types.lazyAttrsOf (lib.types.submodule nixosConfigurationSubmodule);
+ default = { };
+ apply = lib.mapAttrs (lib.const nixosSystem);
+ description = ''
+ Map of configuration names and arguments to `nixosSystem`
+ '';
+ example = lib.literalExpression ''
+ {
+ my-machine = { modules = [ ./configuration.nix ]; };
+ }
+ '';
+ };
+
+ homeConfigurations = lib.mkOption {
+ type = lib.types.lazyAttrsOf (lib.types.submodule homeConfigurationSubmodule);
+ default = { };
+ apply = lib.mapAttrs (lib.const homeManagerConfiguration);
+ description = ''
+ Map of configuration names and arguments to `homeManagerConfiguration`
+ '';
+ example = lib.literalExpression ''
+ {
+ me = { pkgs = nixpkgs.legacyPackages.x86_64-linux; };
+ }
+ '';
+ };
+
+ darwinConfigurations = lib.mkOption {
+ type = lib.types.lazyAttrsOf (lib.types.submodule darwinConfigurationSubmodule);
+ default = { };
+ apply = lib.mapAttrs (lib.const darwinSystem);
+ description = ''
+ Map of configuration names and arguments to `darwinSystem`
+ '';
+ example = lib.literalExpression ''
+ {
+ my-mac = { modules = [ ./darwin-configuration.nix ]; };
+ }
+ '';
+ };
+ };
+
+ config.flake = {
+ inherit (config) nixosConfigurations homeConfigurations darwinConfigurations;
+ /*
+ nixosConfigurations = lib.mapAttrs (lib.const nixosSystem) config.nixosConfigurations;
+ homeConfigurations = lib.mapAttrs (lib.const homeManagerConfiguration) config.homeConfigurations;
+ darwinConfigurations = lib.mapAttrs (lib.const darwinSystem) config.darwinConfigurations;
+ */
+ };
+}
diff --git a/systems/darwin.nix b/systems/darwin.nix
index ec67d09..120e088 100644
--- a/systems/darwin.nix
+++ b/systems/darwin.nix
@@ -1,13 +1,7 @@
-{ self, ... }:
{
- flake = {
- darwinConfigurations =
- let
- # see ./lib/builders.nix
- inherit (self.lib) darwinSystem;
- in
- {
- caroline = darwinSystem { modules = [ ./caroline ]; };
- };
+ darwinConfigurations = {
+ caroline = {
+ modules = [ ./caroline ];
+ };
};
}
diff --git a/systems/nixos.nix b/systems/nixos.nix
index b2a973e..f610ea4 100644
--- a/systems/nixos.nix
+++ b/systems/nixos.nix
@@ -1,17 +1,17 @@
-{ self, ... }:
+{ inputs, ... }:
{
- flake = {
- nixosConfigurations =
- let
- # see ./lib/builders.nix
- inherit (self.lib) nixosSystem nixosSystemStable;
- in
- {
- glados = nixosSystem { modules = [ ./glados ]; };
+ nixosConfigurations = {
+ glados = {
+ modules = [ ./glados ];
+ };
- glados-wsl = nixosSystem { modules = [ ./glados-wsl ]; };
+ glados-wsl = {
+ modules = [ ./glados-wsl ];
+ };
- atlas = nixosSystemStable { modules = [ ./atlas ]; };
- };
+ atlas = {
+ nixpkgs = inputs.nixpkgs-stable;
+ modules = [ ./atlas ];
+ };
};
}
diff --git a/users/default.nix b/users/default.nix
index 6ead5c3..bb0f198 100644
--- a/users/default.nix
+++ b/users/default.nix
@@ -1,16 +1,7 @@
-{ self, withSystem, ... }:
{
- flake.homeConfigurations =
- let
- # see ./lib/builders.nix
- inherit (self.lib) homeManagerConfiguration;
-
- pkgsFor = system: withSystem system ({ pkgs, ... }: pkgs);
- in
- {
- seth = homeManagerConfiguration {
- pkgs = pkgsFor "x86_64-linux";
- modules = [ ./seth/home.nix ];
- };
+ homeConfigurations = {
+ seth = {
+ modules = [ ./seth/home.nix ];
};
+ };
}