feat(configurations)!: flatten down, introduce meta.nix

Flatten down directory structure:
- From: `./hosts/${configuration-type}/${system}/{configuration,deploy}.nix`
-   To: `./hosts/${configuration-type}/{meta,configuration}.nix`
Keep `system` and `deploy-rs` config in `meta.nix`
Update `flake.lock`
This commit is contained in:
reo101 2024-08-13 15:53:14 +03:00
parent 29738555b1
commit 9b8f894a1a
Signed by: reo101
GPG key ID: 675AA7EF13964ACB
43 changed files with 459 additions and 344 deletions

View file

@ -14,11 +14,11 @@
"systems": "systems" "systems": "systems"
}, },
"locked": { "locked": {
"lastModified": 1722339003, "lastModified": 1723293904,
"narHash": "sha256-ZeS51uJI30ehNkcZ4uKqT4ZDARPyqrHADSKAwv5vVCU=", "narHash": "sha256-b+uqzj+Wa6xgMS9aNbX4I+sXeb5biPDi39VgvSFqFvU=",
"owner": "ryantm", "owner": "ryantm",
"repo": "agenix", "repo": "agenix",
"rev": "3f1dae074a12feb7327b4bf43cbac0d124488bb7", "rev": "f6291c5935fdc4e0bef208cfc0dcab7e3f7a1c41",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -37,11 +37,11 @@
"pre-commit-hooks": "pre-commit-hooks" "pre-commit-hooks": "pre-commit-hooks"
}, },
"locked": { "locked": {
"lastModified": 1722299223, "lastModified": 1722597419,
"narHash": "sha256-+5HNJBXb9YXKSmi2TJsnftrgU/msF/4jBAMH9J1bc5c=", "narHash": "sha256-YbMzll0Dh2ln/TryDP+S3IGm8nRHkzcSQIubI4ZEOAw=",
"owner": "oddlama", "owner": "oddlama",
"repo": "agenix-rekey", "repo": "agenix-rekey",
"rev": "4107b53b152f4ddc504269ec17c4b7005869d762", "rev": "126b4a5133eb361cbf5bf90e44c71b6f830845ec",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -175,11 +175,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1722476845, "lastModified": 1723426710,
"narHash": "sha256-7gZ8uf3qOox8Vrwd+p9EhUHHLhhK8lis/5KcXGmIaow=", "narHash": "sha256-yrS9al6l3fYfFfvovnyBWnyELDQOdfKyai4K/jKgoBw=",
"owner": "nix-community", "owner": "nix-community",
"repo": "disko", "repo": "disko",
"rev": "7e1b215a0a96efb306ad6440bf706d2b307dc267", "rev": "0d510fe40b56ed74907a021d7e1ffd0042592914",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -367,11 +367,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1719994518, "lastModified": 1722555600,
"narHash": "sha256-pQMhCCHyQGRzdfAkdJ4cIWiw+JNuWsTX7f0ZYSyz0VY=", "narHash": "sha256-XOQkdLafnb/p9ij77byFQjDf5m5QYl9b2REiVClC+x4=",
"owner": "hercules-ci", "owner": "hercules-ci",
"repo": "flake-parts", "repo": "flake-parts",
"rev": "9227223f6d922fee3c7b190b2cc238a99527bbb7", "rev": "8471fe90ad337a8074e957b69ca4d0089218391d",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -576,11 +576,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1721042469, "lastModified": 1723202784,
"narHash": "sha256-6FPUl7HVtvRHCCBQne7Ylp4p+dpP3P/OYuzjztZ4s70=", "narHash": "sha256-qbhjc/NEGaDbyy0ucycubq4N3//gDFFH3DOmp1D3u1Q=",
"owner": "cachix", "owner": "cachix",
"repo": "git-hooks.nix", "repo": "git-hooks.nix",
"rev": "f451c19376071a90d8c58ab1a953c6e9840527fd", "rev": "c7012d0c18567c889b948781bc74a501e92275d1",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -678,11 +678,11 @@
}, },
"hardware": { "hardware": {
"locked": { "locked": {
"lastModified": 1722332872, "lastModified": 1723310128,
"narHash": "sha256-2xLM4sc5QBfi0U/AANJAW21Bj4ZX479MHPMPkB+eKBU=", "narHash": "sha256-IiH8jG6PpR4h9TxSGMYh+2/gQiJW9MwehFvheSb5rPc=",
"owner": "nixos", "owner": "nixos",
"repo": "nixos-hardware", "repo": "nixos-hardware",
"rev": "14c333162ba53c02853add87a0000cbd7aa230c2", "rev": "c54cf53e022b0b3c1d3b8207aa0f9b194c24f0cf",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -720,11 +720,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1722462338, "lastModified": 1723399884,
"narHash": "sha256-ss0G8t8RJVDewA3MyqgAlV951cWRK6EtVhVKEZ7J5LU=", "narHash": "sha256-97wn0ihhGqfMb8WcUgzzkM/TuAxce2Gd20A8oiruju4=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "6e090576c4824b16e8759ebca3958c5b09659ee8", "rev": "086f619dd991a4d355c07837448244029fc2d9ab",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -756,11 +756,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1722491724, "lastModified": 1723367191,
"narHash": "sha256-pvZ0sqDNhcUzYXrCF9UYZBf+qd3ri/0fT0b4mFqVuBs=", "narHash": "sha256-noi5tre7BLtxImN38jEHeVOtOG1Xu37sJFwHKSAPHjo=",
"owner": "Jovian-Experiments", "owner": "Jovian-Experiments",
"repo": "Jovian-NixOS", "repo": "Jovian-NixOS",
"rev": "ff83ee27a56651dcd6d4c9b3e3b7c08267dc52ae", "rev": "91178062f365b64eece94c5dff93e09b07e87d9d",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -827,11 +827,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1722471252, "lastModified": 1723528508,
"narHash": "sha256-rgNPBiWN+y2jBiXIEgV/McBfkPeZax80eol0FBoupCk=", "narHash": "sha256-4++qlOlqMoZz3h/g48f+TY3r75h+EBToRNmgcVWKpsE=",
"owner": "nix-community", "owner": "nix-community",
"repo": "neovim-nightly-overlay", "repo": "neovim-nightly-overlay",
"rev": "fe7178b41d84add25c63a695620629050fb35bbd", "rev": "f019c7b0e7f478e4aaf2b406785a8d6ec6d1957d",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -843,11 +843,11 @@
"neovim-src": { "neovim-src": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1722463651, "lastModified": 1723504195,
"narHash": "sha256-3YorBqxT1RpL3Z2rLDCJhG+1HnBsgjrW8AOlTkFWlbA=", "narHash": "sha256-Tt+UtP3iSQATu2CUgFgtPkobASE7Rbf2AWZeLH8fthU=",
"owner": "neovim", "owner": "neovim",
"repo": "neovim", "repo": "neovim",
"rev": "e820474cde09273608be5f57e1032aab21e3c97d", "rev": "9768e88f3891b5594eb2d556bd3bdf40c61d46e1",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -882,11 +882,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1722500642, "lastModified": 1722924007,
"narHash": "sha256-Vls0TQRdplex1JslnBxEk3M26Q1vR+OSg+sk5rBG4DA=", "narHash": "sha256-+CQDamNwqO33REJLft8c26NbUi2Td083hq6SvAm2xkU=",
"owner": "lnl7", "owner": "lnl7",
"repo": "nix-darwin", "repo": "nix-darwin",
"rev": "b47af8628624856ad6853168298f1f96364d92d6", "rev": "91010a5613ffd7ee23ee9263213157a1c422b705",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -1123,11 +1123,11 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1722421184, "lastModified": 1723362943,
"narHash": "sha256-/DJBI6trCeVnasdjUo9pbnodCLZcFqnVZiLUfqLH4jA=", "narHash": "sha256-dFZRVSgmJkyM0bkPpaYRtG/kRMRTorUIDj8BxoOt1T4=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "9f918d616c5321ad374ae6cb5ea89c9e04bf3e58", "rev": "a58bc8ad779655e790115244571758e8de055e3d",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -1225,11 +1225,11 @@
}, },
"nur": { "nur": {
"locked": { "locked": {
"lastModified": 1722577920, "lastModified": 1723549487,
"narHash": "sha256-+Nilyq9pr3f13pNqE3UaJ/zxB69fQ8MmkA5xu6oYtIs=", "narHash": "sha256-65NYBcYUx0DjL7TGlesle5PdtJVfOCPnv5zvsgB/dRw=",
"owner": "nix-community", "owner": "nix-community",
"repo": "NUR", "repo": "NUR",
"rev": "a3f8a8853ee2e17c2efd5a33a5c91c1d79bc9c49", "rev": "20b1fc4032363116a880dc64e3fa96f8a24d4e64",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -1701,11 +1701,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1722558337, "lastModified": 1723551051,
"narHash": "sha256-001MFcaVzqfl/d+dhAz4FTWHlHCYU/7nZ9OVWiYLkeI=", "narHash": "sha256-+H7sSt93MLs82ZVdhuHlUPfUL+anMvR3+UrVyZTIxjo=",
"owner": "mitchellh", "owner": "mitchellh",
"repo": "zig-overlay", "repo": "zig-overlay",
"rev": "93eec9c6ff998133fdeed5eb96c4c59fc2b66b7c", "rev": "2a8a3228bca531f3c4482268f7262dacf372baf6",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -1727,11 +1727,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1722209386, "lastModified": 1723396350,
"narHash": "sha256-GAzXTJUJJIXrAlHkInSDwlnVQPL5BV1Enbj3R4ipGFk=", "narHash": "sha256-f5RTadUCYeGPDI6Y7xDYa6sJsdKFCdtD4WipGxuof3A=",
"owner": "zigtools", "owner": "zigtools",
"repo": "zls", "repo": "zls",
"rev": "eba1489b6ffa6db7f0eaefce6e06d53cd9066f7b", "rev": "3ec8ad16337e5fc391fbdfb394f68f155b2a7a69",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -17,7 +17,6 @@
./modules/flake/modules ./modules/flake/modules
./modules/flake/configurations ./modules/flake/configurations
./modules/flake/agenix ./modules/flake/agenix
./modules/flake/deploy
./modules/flake/topology ./modules/flake/topology
./modules/flake/packages ./modules/flake/packages
./modules/flake/overlays ./modules/flake/overlays
@ -35,19 +34,19 @@
flake = { flake = {
inherit (inputs) self; inherit (inputs) self;
# Automatic modules, see `./modules/flake/modules.nix` # Automatic modules, see `./modules/flake/modules/default.nix`
autoModules.enableAll = true; autoModules.enableAll = true;
# Automatic configurations, see `./modules/flake/configurations.nix` # Automatic configurations, see `./modules/flake/configurations/default.nix`
autoConfigurations.enableAll = true; autoConfigurations.enableAll = true;
# Automatic packages, see `./modules/flake/packages/default.nix` # Automatic packages, see `./modules/flake/packages/default/default.nix`
autoPackages.enable = true; autoPackages.enable = true;
# Automatic overlays, see `./modules/flake/overlays/default.nix` # Automatic overlays, see `./modules/flake/overlays/default/default.nix`
autoOverlays.enable = true; autoOverlays.enable = true;
# Automatic devShells, see `./modules/flake/shells/default.nix` # Automatic devShells, see `./modules/flake/shells/default/default.nix`
autoDevShells.enable = true; autoDevShells.enable = true;
# Templates # Templates

View file

@ -0,0 +1,3 @@
{
system = "x86_64-linux";
}

View file

@ -20,7 +20,7 @@
# Zig # Zig
zigpkgs.master zigpkgs.master
inputs.zls-overlay.packages.x86_64-darwin.default # inputs.zls-overlay.packages.x86_64-darwin.default
]; ];
programs.git = { programs.git = {

View file

@ -0,0 +1,3 @@
{
system = "x86_64-darwin";
}

View file

@ -66,7 +66,7 @@
nurl nurl
# Mail # Mail
# himalaya himalaya
# Java # Java
graalvm-ce graalvm-ce
@ -87,7 +87,7 @@
# Zig # Zig
zigpkgs.master zigpkgs.master
inputs.zls-overlay.packages.${pkgs.system}.default # inputs.zls-overlay.packages.${pkgs.system}.default
# Android # Android
android-tools android-tools

View file

@ -0,0 +1,15 @@
{
system = "aarch64-darwin";
deploy = {
hostname = "localhost";
sshUser = "pavelatanasov";
user = "pavelatanasov";
sudo = "sudo -u";
sshOpts = [ ];
fastConnection = false;
autoRollback = true;
magicRollback = true;
tempPath = "/Users/pavelatanasov/.deploy-rs";
remoteBuild = true;
};
}

View file

@ -0,0 +1,3 @@
{
system = "x86_64-darwin";
}

View file

@ -0,0 +1,3 @@
{
system = "aarch64-linux";
}

View file

@ -0,0 +1,3 @@
{
system = "x86_64-linux";
}

View file

@ -0,0 +1,3 @@
{
system = "x86_64-linux";
}

View file

@ -23,6 +23,7 @@
# services.kanidm = { }; # services.kanidm = { };
age.rekey = { age.rekey = {
# TODO: store in `meta`
hostPubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPopSTZ81UyKp9JSljCLp+Syk51zacjh9fLteqxQ6/aB"; hostPubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPopSTZ81UyKp9JSljCLp+Syk51zacjh9fLteqxQ6/aB";
# masterIdentities = [ "${inputs.self}/secrets/privkey.age" ]; # masterIdentities = [ "${inputs.self}/secrets/privkey.age" ];
# storageMode = "local"; # storageMode = "local";
@ -74,7 +75,10 @@
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
git git
neovim # FIXME: cannot deploy neovim-nightly
# V neovim source
# > error: cannot add path '/nix/store/rhjznh5jdzdkzbnn0fhhvcf9rys0s59d-source' because it lacks a signature by a trusted key
# neovim
]; ];
# NOTE: made with `mkpasswd -m sha-512` # NOTE: made with `mkpasswd -m sha-512`

View file

@ -16,7 +16,7 @@
home.packages = with pkgs; [ home.packages = with pkgs; [
## Core ## Core
neovim # neovim
git git
gnupg gnupg
pciutils # lspci pciutils # lspci

View file

@ -0,0 +1,48 @@
{
# The `system` of the host
system = "x86_64-linux";
# `deploy-rs` configuration
deploy = {
# This is the hostname by which you'll refer to this machine using reploy-rs
hostname = "jeeves.reo101.xyz";
# This is the user that deploy-rs will use when connecting.
# This will default to your own username if not specified anywhere
sshUser = "jeeves";
# This is the user that the profile will be deployed to (will use sudo if not the same as above).
# If `sshUser` is specified, this will be the default (though it will _not_ default to your own username)
user = "root";
# Which sudo command to use. Must accept at least two arguments:
# the user name to execute commands as and the rest is the command to execute
# This will default to "sudo -u" if not specified anywhere.
sudo = "sudo -u";
# This is an optional list of arguments that will be passed to SSH.
sshOpts = [ "-p" "727" ];
# Fast connection to the node. If this is true, copy the whole closure instead of letting the node substitute.
# This defaults to `false`
fastConnection = false;
# If the previous profile should be re-activated if activation fails.
# This defaults to `true`
autoRollback = true;
# See the earlier section about Magic Rollback for more information.
# This defaults to `true`
magicRollback = true;
# The path which deploy-rs will use for temporary files, this is currently only used by `magicRollback` to create an inotify watcher in for confirmations
# If not specified, this will default to `/tmp`
# (if `magicRollback` is in use, this _must_ be writable by `user`)
tempPath = "/tmp";
# Build the derivation on the target system
# Will also fetch all external dependencies from the target system's substituters.
# This default to `false`
remoteBuild = true;
};
}

View file

@ -1,42 +0,0 @@
{
# This is the hostname by which you'll refer to this machine using reploy-rs
hostname = "jeeves.reo101.xyz";
# This is the user that deploy-rs will use when connecting.
# This will default to your own username if not specified anywhere
sshUser = "jeeves";
# This is the user that the profile will be deployed to (will use sudo if not the same as above).
# If `sshUser` is specified, this will be the default (though it will _not_ default to your own username)
user = "root";
# Which sudo command to use. Must accept at least two arguments:
# the user name to execute commands as and the rest is the command to execute
# This will default to "sudo -u" if not specified anywhere.
sudo = "sudo -u";
# This is an optional list of arguments that will be passed to SSH.
sshOpts = [ "-p" "727" ];
# Fast connection to the node. If this is true, copy the whole closure instead of letting the node substitute.
# This defaults to `false`
fastConnection = false;
# If the previous profile should be re-activated if activation fails.
# This defaults to `true`
autoRollback = true;
# See the earlier section about Magic Rollback for more information.
# This defaults to `true`
magicRollback = true;
# The path which deploy-rs will use for temporary files, this is currently only used by `magicRollback` to create an inotify watcher in for confirmations
# If not specified, this will default to `/tmp`
# (if `magicRollback` is in use, this _must_ be writable by `user`)
tempPath = "/tmp";
# Build the derivation on the target system
# Will also fetch all external dependencies from the target system's substituters.
# This default to `false`
remoteBuild = true;
}

View file

@ -6,11 +6,12 @@ let
hasFiles hasFiles
hasDirectories hasDirectories
recurseDir recurseDir
configuration-type-to-outputs-modules; kebabToCamel
configuration-type-to-outputs-modules
configuration-type-to-outputs-configurations;
in in
let let
# Configuration helpers # Configuration helpers
configurationTypes = ["nixos" "nix-on-droid" "nix-darwin" "home-manager"];
# `pkgs` with flake's overlays # `pkgs` with flake's overlays
# NOTE: done here to avoid infinite recursion # NOTE: done here to avoid infinite recursion
@ -18,7 +19,15 @@ let
(withSystem system ({ pkgs, ... }: pkgs)).extend (withSystem system ({ pkgs, ... }: pkgs)).extend
(final: prev: inputs.self.packages.${system}); (final: prev: inputs.self.packages.${system});
homeManagerModule = { root, system, hostname, users ? null }: { genUsers = configurationFiles:
lib.pipe configurationFiles [
(cf: cf."home" or { })
builtins.attrNames
(builtins.map
(lib.strings.removeSuffix ".nix"))
];
homeManagerModule = { root, meta, users ? null }: {
home-manager = { home-manager = {
# Use same `pkgs` instance as system (i.e. carry over overlays) # Use same `pkgs` instance as system (i.e. carry over overlays)
useGlobalPkgs = true; useGlobalPkgs = true;
@ -26,11 +35,10 @@ let
useUserPackages = true; useUserPackages = true;
# Default import all of our exported `home-manager` modules # Default import all of our exported `home-manager` modules
sharedModules = builtins.attrValues config.flake.${configuration-type-to-outputs-modules "home-manager"}; sharedModules = builtins.attrValues config.flake.${configuration-type-to-outputs-modules "home-manager"};
# Pass in `inputs`, `outputs` and maybe `meta` # Pass in `inputs`, `hostname` and `meta`
extraSpecialArgs = { extraSpecialArgs = {
inherit inputs; inherit inputs;
# TODO: meta? inherit meta;
inherit hostname;
}; };
} // (if users == null then { } // (if users == null then {
# nixOnDroid # nixOnDroid
@ -44,9 +52,9 @@ let
}); });
}; };
mkNixosHost = args @ { root, system, hostname, users }: inputs.nixpkgs.lib.nixosSystem { mkNixosHost = args @ { root, meta, users }: inputs.nixpkgs.lib.nixosSystem {
inherit system; inherit (meta) system;
pkgs = pkgs' system; pkgs = pkgs' meta.system;
modules = [ modules = [
# Main configuration # Main configuration
@ -61,19 +69,21 @@ let
inputs.nix-topology.nixosModules.default inputs.nix-topology.nixosModules.default
# Sane default `networking.hostName` # Sane default `networking.hostName`
{ {
networking.hostName = lib.mkDefault hostname; networking.hostName = lib.mkDefault meta.hostname;
} }
# TODO: lib.optionals
] ++ (builtins.attrValues config.flake.${configuration-type-to-outputs-modules "nixos"}); ] ++ (builtins.attrValues config.flake.${configuration-type-to-outputs-modules "nixos"});
specialArgs = { specialArgs = {
inherit inputs; inherit inputs;
inherit meta;
}; };
}; };
mkNixOnDroidHost = args @ { root, system, hostname }: inputs.nix-on-droid.lib.nixOnDroidConfiguration { mkNixOnDroidHost = args @ { root, meta }: inputs.nix-on-droid.lib.nixOnDroidConfiguration {
# NOTE: inferred by `pkgs.system` # NOTE: inferred by `pkgs.system`
# inherit system; # inherit system;
pkgs = pkgs' system; pkgs = pkgs' meta.system;
modules = [ modules = [
# Main configuration # Main configuration
@ -84,14 +94,15 @@ let
extraSpecialArgs = { extraSpecialArgs = {
inherit inputs; inherit inputs;
inherit meta;
}; };
home-manager-path = inputs.home-manager.outPath; home-manager-path = inputs.home-manager.outPath;
}; };
mkNixDarwinHost = args @ { root, system, hostname, users }: inputs.nix-darwin.lib.darwinSystem { mkNixDarwinHost = args @ { root, meta, users }: inputs.nix-darwin.lib.darwinSystem {
inherit system; inherit (meta) system;
pkgs = pkgs' system; pkgs = pkgs' meta.system;
modules = [ modules = [
# Main configuration # Main configuration
@ -107,12 +118,13 @@ let
specialArgs = { specialArgs = {
inherit inputs; inherit inputs;
inherit meta;
}; };
}; };
mkHomeManagerHost = args @ { root, system, hostname }: inputs.home-manager.lib.homeManagerConfiguration { mkHomeManagerHost = args @ { root, meta }: inputs.home-manager.lib.homeManagerConfiguration {
inherit system; inherit (meta) system;
pkgs = pkgs' system; pkgs = pkgs' meta.system;
modules = [ modules = [
"${root}/home.nix" "${root}/home.nix"
@ -120,30 +132,9 @@ let
extraSpecialArgs = { extraSpecialArgs = {
inherit inputs; inherit inputs;
inherit hostname; inherit meta;
}; };
}; };
createConfigurations =
pred: mkHost: hosts:
lib.foldAttrs
lib.const
[ ]
(builtins.attrValues
(builtins.mapAttrs
(system: hosts:
lib.concatMapAttrs
(host: configurationFiles:
lib.optionalAttrs
(and [
(host != "__template__")
(pred { inherit system host configurationFiles; })
])
{
${host} = mkHost { inherit system host configurationFiles; };
})
hosts)
hosts));
in in
{ {
options = let options = let
@ -153,9 +144,18 @@ in
description = '' description = ''
Automagically generate configurations from walking directories with Nix files Automagically generate configurations from walking directories with Nix files
''; '';
type = types.submodule (submodule: { internal = true;
type = types.submodule (autoConfigurationsSubmodule: let
inherit (autoConfigurationsSubmodule.config)
configurationTypes
enableAll
baseDir
;
in {
options = { options = {
enableAll = lib.mkEnableOption "Automatic ${builtins.toString configurationTypes} configurations extraction"; enableAll = lib.mkEnableOption ''
Automatic ${builtins.toString (lib.attrValues configurationTypes)} configurations extraction
'';
baseDir = lib.mkOption { baseDir = lib.mkOption {
description = '' description = ''
Base directory of the contained configurations, used as a base for the rest of the options Base directory of the contained configurations, used as a base for the rest of the options
@ -164,135 +164,291 @@ in
default = "${self}/hosts"; default = "${self}/hosts";
defaultText = ''''${self}/hosts''; defaultText = ''''${self}/hosts'';
}; };
} // ( configurationTypes = lib.mkOption {
lib.pipe type = types.attrsOf (types.submodule (configurationTypeSubmodule@{ name, ... }: let
configurationTypes inherit (configurationTypeSubmodule.config)
[ # enable
(builtins.map dir
# NOTE: create small submodule for every `configurationType` predicate
(configurationType: mkHost
lib.nameValuePair mkDeployNode
"${configurationType}" ;
(lib.mkOption { in {
type = types.submodule { options = {
options = { enable = lib.mkEnableOption "Automatic ${name} configurations extraction" // {
# NOTE: each can be enabled (default global `enableAll`) default = enableAll;
enable = lib.mkEnableOption "Automatic ${configurationType} configurations extraction" // { };
default = submodule.config.enableAll; # NOTE: each can be read from a different directory
}; dir = lib.mkOption {
# NOTE: each can be read from a different directory type = types.path;
# (default global `baseDir` + `camelToKebab`-ed `configurationType`) default = "${baseDir}/${name}";
dir = lib.mkOption { };
type = types.path; hostsName = lib.mkOption {
default = "${submodule.config.baseDir}/${configurationType}"; description = ''
}; Name of the `hosts` output
# TODO: split hosts and configurations? '';
resultHosts = lib.mkOption { type = types.str;
description = '' default = "${kebabToCamel name}Hosts";
The resulting automatic packages };
''; configurationsName = lib.mkOption {
# TODO: specify description = ''
type = types.unspecified; Name of the `configurations` output
readOnly = true; '';
internal = true; type = types.str;
default = default = "${kebabToCamel name}Configurations";
lib.optionalAttrs };
config.flake.autoConfigurations.${configurationType}.enable predicate = lib.mkOption {
(recurseDir config.flake.autoConfigurations.${configurationType}.dir); description = ''
Function for filtering configurations
'';
# FIXME: `merge` of `functionTo` type causes a stray `passthru` to attempt getting evaluated
# type = types.functionTo types.anything;
type = types.unspecified;
example = /* nix */ ''
{ root, host, configurationFiles, ... }:
# Utils from `./modules/flake/lib/default.nix`
and [
(! (host == "__template__"))
(hasFiles
[ "configuration.nix" ]
configurationFiles)
(hasDirectories
[ "home" ]
configurationFiles)
]
'';
};
mkHost = lib.mkOption {
description = ''
Function for generating a configuration
'';
# type = types.functionTo types.anything;
type = types.unspecified;
example = /* nix */ ''
args @ { root, meta, users }: inputs.nixpkgs.lib.nixosSystem {
inherit (meta) system;
modules = [
# Main configuration
"''${root}/configuration.nix"
# Home Manager
inputs.home-manager.nixosModules.home-manager
(homeManagerModule args)
] ++ (builtins.attrValues config.flake.''${configuration-type-to-outputs-modules "nixos"});
specialArgs = {
inherit inputs;
inherit meta;
}; };
}; };
'';
};
mkDeployNode = lib.mkOption {
description = ''
Function for generating a `deploy-rs` node (null to skip)
'';
type = types.nullOr (types.functionTo types.anything);
default = null;
# TODO: update
example = /* nix */ ''
args @ { root, host, meta, configuration }:
inputs.deploy-rs.''${meta.system}.activate.nixos configuration;
'';
};
resultConfigurations = lib.mkOption {
description = ''
The resulting automatic configurations
'';
# TODO: specify
type = types.unspecified;
readOnly = true;
default =
lib.pipe dir [
recurseDir
(lib.concatMapAttrs
(host: configurationFiles:
let
root = "${dir}/${host}";
meta-path = "${root}/meta.nix";
meta = import meta-path;
deploy-config = meta.deploy or null;
has-mkDeployNode = mkDeployNode != null;
has-deploy-config = builtins.pathExists meta-path && deploy-config != null;
configuration-args = { inherit root host configurationFiles; };
valid = predicate configuration-args;
configuration = mkHost configuration-args;
deploy-args = { inherit root host meta configuration; };
deploy = mkDeployNode deploy-args;
in
lib.optionalAttrs valid {
${host} = {
inherit configuration;
} // lib.optionalAttrs (has-mkDeployNode && has-deploy-config) {
inherit deploy;
};
}))
];
};
};
config = {};
}));
# TODO: put in a more visible place
default = {
nixos = {
predicate = ({ root, host, configurationFiles, ... }:
and [
(! (host == "__template__"))
(hasFiles
[ "configuration.nix" "meta.nix" ]
configurationFiles)
]);
mkHost = ({ root, host, configurationFiles, ... }: let
meta = import "${root}/meta.nix" // {
hostname = host;
}; };
default = {}; in
}))) mkNixosHost {
builtins.listToAttrs inherit root;
]); inherit meta;
users = genUsers configurationFiles;
});
mkDeployNode = ({ root, host, meta, configuration }:
{
inherit (meta.deploy) hostname;
profiles.system = meta.deploy // {
path = inputs.deploy-rs.lib.${meta.system}.activate."nixos" configuration;
};
});
};
nix-on-droid = {
predicate = ({ root, host, configurationFiles, ... }:
and [
(! (host == "__template__"))
(hasFiles
[ "configuration.nix" "home.nix" "meta.nix" ]
configurationFiles)
]);
mkHost = ({ root, host, configurationFiles, ... }: let
meta = import "${root}/meta.nix" // {
hostname = host;
};
in
mkNixOnDroidHost {
inherit root;
inherit meta;
});
};
nix-darwin = {
hostsName = "darwinHosts";
configurationsName = "darwinConfigurations";
predicate = ({ root, host, configurationFiles, ... }:
and [
(! (host == "__template__"))
(hasFiles
[ "configuration.nix" "meta.nix" ]
configurationFiles)
(hasDirectories
[ "home" ]
configurationFiles)
]);
mkHost = ({ root, host, configurationFiles, ... }: let
meta = import "${root}/meta.nix" // {
hostname = host;
};
in
mkNixDarwinHost {
inherit root;
inherit meta;
users = genUsers configurationFiles;
});
mkDeployNode = ({ root, host, meta, configuration }:
{
inherit (meta.deploy) hostname;
profiles.system = meta.deploy // {
path = inputs.deploy-rs.lib.${meta.system}.activate."darwin" configuration;
};
});
};
home-manager = {
hostsName = "homeHosts";
configurationsName = "homeConfigurations";
predicate = ({ root, host, configurationFiles, ... }:
and [
(! (host == "__template__"))
(hasFiles
[ "home.nix" "meta.nix" ]
configurationFiles)
]);
mkHost = ({ root, host, configurationFiles, ... }: let
meta = import "${root}/meta.nix" // {
hostname = host;
};
in
mkHomeManagerHost {
inherit root;
inherit meta;
});
};
};
};
resultConfigurations = lib.mkOption {
readOnly = true;
default = lib.pipe configurationTypes [
(lib.mapAttrs'
(configurationType: configurationTypeConfig:
lib.nameValuePair
configurationTypeConfig.configurationsName
(lib.mapAttrs
(host: { configuration, ... }:
configuration)
configurationTypeConfig.resultConfigurations)))
];
};
resultDeployNodes = lib.mkOption {
readOnly = true;
default = lib.pipe configurationTypes [
(lib.concatMapAttrs
(configurationType: configurationTypeConfig:
(lib.concatMapAttrs
(host: { deploy ? null, ... }:
lib.optionalAttrs
(deploy != null)
{
${host} = deploy;
})
configurationTypeConfig.resultConfigurations)))
];
};
};
}); });
default = {}; default = {};
}; };
}; };
config = { config = {
flake = { # BUG: cannot iterate on `config.flake.autoConfigurations.resultConfigurations`
# Configurations # because of infinite recursion
nixosConfigurations = flake = let
createConfigurations ogConfigurationTypes = ["nixos" "nix-on-droid" "nix-darwin" "home-manager"];
({ system, host, configurationFiles, ... }: configurations = lib.pipe ogConfigurationTypes [
and (lib.map
[ configuration-type-to-outputs-configurations)
(hasFiles (lib.flip lib.genAttrs
[ "configuration.nix" ] (configurationType:
configurationFiles) config.flake.autoConfigurations.resultConfigurations.${configurationType}))
# (hasDirectories ];
# [ "home" ] deployNodes = {
# config) deploy.nodes = config.flake.autoConfigurations.resultDeployNodes;
]) };
({ system, host, configurationFiles, ... }: deployChecks = {
mkNixosHost { checks =
root = "${config.flake.autoConfigurations.nixos.dir}/${system}/${host}"; lib.mapAttrs
inherit system; (system: deployLib:
hostname = host; deployLib.deployChecks
users = (builtins.map self.deploy)
(lib.strings.removeSuffix ".nix") inputs.deploy-rs.lib;
(builtins.attrNames (configurationFiles."home" or { }))); };
}) # TODO: lib.something for merging (asserting for no overwrites)
config.flake.autoConfigurations.nixos.resultHosts; in configurations // deployNodes // deployChecks;
nixOnDroidConfigurations =
createConfigurations
({ system, host, configurationFiles, ... }:
and
[
(hasFiles
[ "configuration.nix" "home.nix" ]
configurationFiles)
])
({ system, host, configurationFiles, ... }:
mkNixOnDroidHost {
root = "${config.flake.autoConfigurations.nix-on-droid.dir}/${system}/${host}";
inherit system;
hostname = host;
})
config.flake.autoConfigurations.nix-on-droid.resultHosts;
darwinConfigurations =
createConfigurations
({ system, host, configurationFiles, ... }:
and
[
(hasFiles
[ "configuration.nix" ]
configurationFiles)
(hasDirectories
[ "home" ]
configurationFiles)
])
({ system, host, configurationFiles, ... }:
mkNixDarwinHost {
root = "${config.flake.autoConfigurations.nix-darwin.dir}/${system}/${host}";
inherit system;
hostname = host;
users = (builtins.map
(lib.strings.removeSuffix ".nix")
(builtins.attrNames (configurationFiles."home" or { })));
})
config.flake.autoConfigurations.nix-darwin.resultHosts;
homeConfigurations =
createConfigurations
({ system, host, configurationFiles, ... }:
and
[
(hasFiles
[ "home.nix" ]
configurationFiles)
])
({ system, host, configurationFiles, ... }:
mkHomeManagerHost {
root = "${config.flake.autoConfigurations.home-manager.dir}/${system}/${host}";
inherit system;
hostname = host;
})
config.flake.autoConfigurations.home-manager.resultHosts;
};
}; };
} }

View file

@ -1,45 +0,0 @@
{ lib, config, self, inputs, ... }:
let
inherit (config.lib)
accumulateHosts
configuration-type-to-deploy-type;
in
{
flake = {
deploy.nodes =
accumulateHosts
# TODO: nix-on-droid
["nixos" "nix-darwin"]
({ host, system, configuration-type, configuration }:
let
deploy-config-path =
"${config.flake.autoConfigurations.${configuration-type}.dir}/${system}/${host}/deploy.nix";
deploy-config =
import deploy-config-path;
in
lib.optionalAttrs
(builtins.pathExists deploy-config-path)
{
${host} = {
inherit (deploy-config)
hostname;
profiles.system = deploy-config // {
path =
let
deploy-type = configuration-type-to-deploy-type configuration-type;
in
inputs.deploy-rs.lib.${system}.activate.${deploy-type} configuration;
};
};
}
);
checks =
lib.mapAttrs
(system: deployLib:
deployLib.deployChecks
self.deploy)
inputs.deploy-rs.lib;
};
}

View file

@ -121,43 +121,5 @@
(configuration-type: (configuration-type:
builtins.throw builtins.throw
"Invaild configuration-type \"${configuration-type}\" for deploy-rs deployment"); "Invaild configuration-type \"${configuration-type}\" for deploy-rs deployment");
accumulateHosts = configuration-types: host-system-configuration-type-configuration-fn:
lib.flip lib.concatMapAttrs
(lib.genAttrs
configuration-types
(configuration-type:
config.flake.autoConfigurations.${configuration-type}.resultHosts))
(configuration-type: hosts:
lib.pipe
hosts
[
# Filter out nondirectories
(lib.filterAttrs
(system: configurations:
builtins.isAttrs configurations))
# Convert non-template configs into `system-and-config` pairs
(lib.concatMapAttrs
(system: configurations:
(lib.concatMapAttrs
(host: configuration:
lib.optionalAttrs
(host != "__template__")
{
${host} = {
inherit system;
configuration =
let
configurations = configuration-type-to-outputs-configurations configuration-type;
in
self.${configurations}.${host};
};
})
configurations)))
# Convert each `system-and-config` pair into a *whatever*
(lib.concatMapAttrs
(host: { system, configuration }:
host-system-configuration-type-configuration-fn { inherit host system configuration-type configuration; }))
]);
}; };
} }