Skip to content

Commit

Permalink
add support for system-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
zimbatm committed Feb 3, 2025
1 parent c0508d7 commit 48eaa11
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
27 changes: 26 additions & 1 deletion docs/folder-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pkgs.mkShell {
}
```

### `hosts/<hostname>/(default.nix|configuration.nix|darwin-configuration.nix)`
### `hosts/<hostname>/(default.nix|configuration.nix|darwin-configuration.nix,system-configuration.nix)`

Each folder contains either a NixOS or nix-darwin configuration:

Expand Down Expand Up @@ -123,6 +123,31 @@ Flake outputs:
* `darwinConfiguration.<hostname>`
* `checks.<system>.darwin-<hostname>` - contains the system closure.

#### `system-configuration.nix`

Evaluates to a [system-manager](https://github.com/numtide/system-manager)
configuration.

To support it, also add the following lines to the `flake.nix` file:

```nix
{
inputs.system-manager.url = "github:numtide/system-manager";
}
```

Additional values passed:

* `inputs` maps to the current flake inputs.
* `flake` maps to `inputs.self`.
* `perSystem`: contains the packages of all the inputs, filtered per system.
Eg: `perSystem.nixos-anywhere.default` is a shorthand for `inputs.nixos-anywhere.packages.<system>.default`.

Flake outputs:

* `systemConfiguration.<hostname>`
* `checks.<system>.system-<hostname>` - contains the system closure.

#### `default.nix`

If present, this file takes precedence over `configuration.nix` and `darwin-configuration.nix` and is designed as an
Expand Down
29 changes: 29 additions & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,24 @@ let
};
};

loadSystemManager =
_hostname: path:
let
system-manager =
inputs.system-manager
or (throw ''${path} depends on system-manager. To fix this, add `inputs.system-manager.url = "github:numtide/system-manager"; to your flake'');
in
{
class = "system-manager";
value = system-manager.lib.makeSystemConfig {
modules = [
perSystemModule
path
];
extraSpecialArgs = specialArgs;
};
};

loadHost =
name:
{ path, type }:
Expand All @@ -307,6 +325,8 @@ let
loadNixOS name (path + "/configuration.nix")
else if builtins.pathExists (path + "/darwin-configuration.nix") then
loadNixDarwin name (path + "/darwin-configuration.nix")
else if builtins.pathExists (path + "/system-configuration.nix") then
loadSystemManager name (path + "/system-configuration.nix")
else if builtins.hasAttr name homesNested then
# If there are any home configurations defined for this host, they
# must be standalone configurations since there is no OS config.
Expand All @@ -327,6 +347,8 @@ let
"nixosConfigurations"
else if x.value.class == "nix-darwin" then
"darwinConfigurations"
else if x.value.class == "system-manager" then
"systemConfigs"
else
throw "host '${x.name}' of class '${x.value.class or "unknown"}' not supported"
) (lib.attrsToList hosts)
Expand Down Expand Up @@ -466,6 +488,7 @@ let

darwinConfigurations = lib.mapAttrs (_: x: x.value) (hostsByCategory.darwinConfigurations or { });
nixosConfigurations = lib.mapAttrs (_: x: x.value) (hostsByCategory.nixosConfigurations or { });
systemConfigs = lib.mapAttrs (_: x: x.value) (hostsByCategory.systemConfigs or { });

inherit modules;

Expand Down Expand Up @@ -522,6 +545,12 @@ let
lib.filterAttrs (_: x: x.pkgs.system == system) (inputs.self.darwinConfigurations or { })
)
))
# add system-manager closures to checks
(withPrefix "system-" (
lib.mapAttrs (_: x: x) (
lib.filterAttrs (_: x: x.system == system) (inputs.self.systemConfigs or { })
)
))
# load checks from the /checks folder. Those take precedence over the others.
(filterPlatforms system (
optionalPathAttrs (src + "/checks") (
Expand Down
15 changes: 15 additions & 0 deletions templates/system-manager/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
description = "blueprint+system-manager example";

# Add all your dependencies here
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
blueprint.url = "github:numtide/blueprint";
blueprint.inputs.nixpkgs.follows = "nixpkgs";
system-manager.url = "github:numtide/system-manager";
system-manager.inputs.nixpkgs.follows = "nixpkgs";
};

# Load the blueprint
outputs = inputs: inputs.blueprint { inherit inputs; };
}
14 changes: 14 additions & 0 deletions templates/system-manager/hosts/myhost/system-configuration.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ pkgs, ... }:
{
config = {
nixpkgs.hostPlatform = "x86_64-linux";

services.nginx.enable = true;

environment = {
systemPackages = [
pkgs.ripgrep
];
};
};
}

0 comments on commit 48eaa11

Please sign in to comment.