feat!(flake): convert to fs-defined configurations
Place all configurations in `machines/${manager}/${system}/${hostname}/...`: - `${manager}` - One of `nixos`, `nix-on-droid`, `nix-darwin` or `home-manager` - `${system}` - A system's architecture (can be many) - `${hostname}` - A system's hostname (can be many) The flake now automatically generates the needed configurations based on the above structure. It only generates configurations for valid directory structures: - It wouldn't generate a NixOS config if there isn't a `configuration.nix` file - ...
This commit is contained in:
parent
b0110b3e64
commit
dd2391d905
9 changed files with 176 additions and 66 deletions
138
flake.nix
138
flake.nix
|
@ -67,6 +67,10 @@
|
||||||
} @ inputs:
|
} @ inputs:
|
||||||
let
|
let
|
||||||
inherit (self) outputs;
|
inherit (self) outputs;
|
||||||
|
inherit ((import ./lib/default.nix) { lib = nixpkgs.lib; })
|
||||||
|
recurseDir
|
||||||
|
hasFiles
|
||||||
|
hasDirectories;
|
||||||
forAllSystems = nixpkgs.lib.genAttrs [
|
forAllSystems = nixpkgs.lib.genAttrs [
|
||||||
"aarch64-linux"
|
"aarch64-linux"
|
||||||
"i686-linux"
|
"i686-linux"
|
||||||
|
@ -87,22 +91,32 @@
|
||||||
);
|
);
|
||||||
|
|
||||||
overlays = import ./overlays;
|
overlays = import ./overlays;
|
||||||
|
|
||||||
|
# Modules
|
||||||
nixosModules = import ./modules/nixos;
|
nixosModules = import ./modules/nixos;
|
||||||
nixOnDroidModules = import ./modules/nix-on-droid;
|
nixOnDroidModules = import ./modules/nix-on-droid;
|
||||||
nixDarwinModules = import ./modules/nix-darwin;
|
nixDarwinModules = import ./modules/nix-darwin;
|
||||||
homeManagerModules = import ./modules/home-manager;
|
homeManagerModules = import ./modules/home-manager;
|
||||||
|
|
||||||
nixosConfigurations = {
|
# Machines
|
||||||
# arthur = nixpkgs.lib.nixosSystem {
|
machines = recurseDir ./machines;
|
||||||
# specialArgs = { inherit inputs outputs; };
|
homeManagerMachines = machines.home-manager or {};
|
||||||
# modules = [
|
nixDarwinMachines = machines.nix-darwin or {};
|
||||||
# ./nixos/arthur/configuration.nix
|
nixOnDroidMachines = machines.nix-on-droid or {};
|
||||||
# ];
|
nixosMachines = machines.nixos or {};
|
||||||
# };
|
|
||||||
|
# mkHost helpers
|
||||||
|
mkNixosHost = system: hostname: nixpkgs.lib.nixosSystem {
|
||||||
|
modules = [
|
||||||
|
./machines/nixos/${system}/${hostname}/configuration.nix
|
||||||
|
];
|
||||||
|
|
||||||
|
specialArgs = {
|
||||||
|
inherit inputs outputs;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
nixOnDroidConfigurations =
|
mkNixOnDroidHost = system: hostname: nix-on-droid.lib.nixOnDroidConfiguration {
|
||||||
let mkHost = system: hostname: nix-on-droid.lib.nixOnDroidConfiguration {
|
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
inherit system;
|
inherit system;
|
||||||
|
|
||||||
|
@ -112,7 +126,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
modules = [
|
modules = [
|
||||||
./nix-on-droid/${hostname}/configuration.nix
|
./machines/nix-on-droid/${system}/${hostname}/configuration.nix
|
||||||
{ nix.registry.nixpkgs.flake = nixpkgs; }
|
{ nix.registry.nixpkgs.flake = nixpkgs; }
|
||||||
] ++ (builtins.attrValues nixOnDroidModules);
|
] ++ (builtins.attrValues nixOnDroidModules);
|
||||||
|
|
||||||
|
@ -123,18 +137,11 @@
|
||||||
|
|
||||||
home-manager-path = home-manager.outPath;
|
home-manager-path = home-manager.outPath;
|
||||||
};
|
};
|
||||||
in
|
|
||||||
rec {
|
|
||||||
cheetah = mkHost "aarch64-linux" "cheetah";
|
|
||||||
|
|
||||||
default = cheetah;
|
mkNixDarwinHost = system: hostname: users: nix-darwin.lib.darwinSystem {
|
||||||
};
|
|
||||||
|
|
||||||
darwinConfigurations =
|
|
||||||
let mkHost = system: hostname: users: nix-darwin.lib.darwinSystem {
|
|
||||||
inherit system;
|
inherit system;
|
||||||
modules = [
|
modules = [
|
||||||
./nix-darwin/${hostname}/configuration.nix
|
./machines/nix-darwin/${system}/${hostname}/configuration.nix
|
||||||
home-manager.darwinModules.home-manager
|
home-manager.darwinModules.home-manager
|
||||||
{
|
{
|
||||||
home-manager = {
|
home-manager = {
|
||||||
|
@ -142,7 +149,7 @@
|
||||||
useUserPackages = true;
|
useUserPackages = true;
|
||||||
users = nixpkgs.lib.attrsets.genAttrs
|
users = nixpkgs.lib.attrsets.genAttrs
|
||||||
users
|
users
|
||||||
(user: import ./nix-darwin/${hostname}/home/${user}.nix);
|
(user: import ./machines/nix-darwin/${system}/${hostname}/home/${user}.nix);
|
||||||
|
|
||||||
extraSpecialArgs = { inherit inputs; };
|
extraSpecialArgs = { inherit inputs; };
|
||||||
};
|
};
|
||||||
|
@ -150,19 +157,86 @@
|
||||||
] ++ (builtins.attrValues nixDarwinModules);
|
] ++ (builtins.attrValues nixDarwinModules);
|
||||||
inputs = { inherit inputs outputs nix-darwin nixpkgs; };
|
inputs = { inherit inputs outputs nix-darwin nixpkgs; };
|
||||||
};
|
};
|
||||||
in
|
|
||||||
rec {
|
mkHomeManagerHost = system: hostname: home-manager.lib.homeManagerConfiguration {
|
||||||
apavel-a01 = mkHost "x86_64-darwin" "apavel-a01" [ "apavel" ];
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
modules = [
|
||||||
|
./machines/home-manager/${system}/${hostname}/home.nix
|
||||||
|
];
|
||||||
|
extraSpecialArgs = { inherit inputs outputs; };
|
||||||
};
|
};
|
||||||
|
|
||||||
homeConfigurations = {
|
# Final configurations
|
||||||
# "nix-on-droid@cheetah" = home-manager.lib.homeManagerConfiguration {
|
|
||||||
# pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
nixosConfigurations =
|
||||||
# extraSpecialArgs = { inherit inputs outputs; };
|
nixpkgs.lib.foldAttrs
|
||||||
# modules = [
|
(acc: x: acc)
|
||||||
# ./home-manager/home.nix
|
[]
|
||||||
# ];
|
(builtins.attrValues
|
||||||
# };
|
(builtins.mapAttrs
|
||||||
};
|
(system: hosts:
|
||||||
|
nixpkgs.lib.attrsets.filterAttrs
|
||||||
|
(host: config: config != null)
|
||||||
|
(builtins.mapAttrs
|
||||||
|
(host: config:
|
||||||
|
if (hasFiles [ "configuration.nix" ] config)
|
||||||
|
then mkNixosHost system host
|
||||||
|
else null)
|
||||||
|
hosts))
|
||||||
|
nixosMachines));
|
||||||
|
|
||||||
|
nixOnDroidConfigurations =
|
||||||
|
nixpkgs.lib.foldAttrs
|
||||||
|
(acc: x: acc)
|
||||||
|
[]
|
||||||
|
(builtins.attrValues
|
||||||
|
(builtins.mapAttrs
|
||||||
|
(system: hosts:
|
||||||
|
nixpkgs.lib.attrsets.filterAttrs
|
||||||
|
(host: config: config != null)
|
||||||
|
(builtins.mapAttrs
|
||||||
|
(host: config:
|
||||||
|
if (hasFiles [ "configuration.nix" "home.nix" ] config)
|
||||||
|
then mkNixOnDroidHost system host
|
||||||
|
else null)
|
||||||
|
hosts))
|
||||||
|
nixOnDroidMachines));
|
||||||
|
|
||||||
|
darwinConfigurations =
|
||||||
|
nixpkgs.lib.foldAttrs
|
||||||
|
(acc: x: acc)
|
||||||
|
[]
|
||||||
|
(builtins.attrValues
|
||||||
|
(builtins.mapAttrs
|
||||||
|
(system: hosts:
|
||||||
|
nixpkgs.lib.attrsets.filterAttrs
|
||||||
|
(host: config: config != null)
|
||||||
|
(builtins.mapAttrs
|
||||||
|
(host: config:
|
||||||
|
if (hasFiles [ "configuration.nix" ] config)
|
||||||
|
then mkNixDarwinHost system host
|
||||||
|
(builtins.map
|
||||||
|
(nixpkgs.lib.strings.removeSuffix ".nix")
|
||||||
|
(builtins.attrNames (config."home" or {})))
|
||||||
|
else null)
|
||||||
|
hosts))
|
||||||
|
nixDarwinMachines));
|
||||||
|
|
||||||
|
homeConfigurations =
|
||||||
|
nixpkgs.lib.foldAttrs
|
||||||
|
(acc: x: acc)
|
||||||
|
[]
|
||||||
|
(builtins.attrValues
|
||||||
|
(builtins.mapAttrs
|
||||||
|
(system: hosts:
|
||||||
|
nixpkgs.lib.attrsets.filterAttrs
|
||||||
|
(host: config: config != null)
|
||||||
|
(builtins.mapAttrs
|
||||||
|
(host: config:
|
||||||
|
if (hasFiles [ "home.nix" ] config)
|
||||||
|
then mkNixOnDroidHost system host
|
||||||
|
else null)
|
||||||
|
hosts))
|
||||||
|
homeManagerMachines));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
36
lib/default.nix
Normal file
36
lib/default.nix
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
{ lib, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
inherit (lib) mapAttrs;
|
||||||
|
inherit (lib.attrsets) filterAttrs;
|
||||||
|
in
|
||||||
|
rec {
|
||||||
|
recurseDir = dir:
|
||||||
|
mapAttrs
|
||||||
|
(file: type:
|
||||||
|
if type == "directory"
|
||||||
|
then recurseDir "${dir}/${file}"
|
||||||
|
else type
|
||||||
|
)
|
||||||
|
(builtins.readDir dir);
|
||||||
|
|
||||||
|
# VVV - Implying `attrs` is the output of `recurseDir` - VVV
|
||||||
|
|
||||||
|
hasFiles = files: attrs:
|
||||||
|
builtins.all
|
||||||
|
(b: b)
|
||||||
|
(builtins.map
|
||||||
|
(file:
|
||||||
|
builtins.hasAttr file attrs &&
|
||||||
|
builtins.getAttr file attrs == "regular")
|
||||||
|
files);
|
||||||
|
|
||||||
|
hasDirectories = directories: attrs:
|
||||||
|
builtins.all
|
||||||
|
(b: b)
|
||||||
|
(builtins.map
|
||||||
|
(directory:
|
||||||
|
builtins.hasAttr directory attrs &&
|
||||||
|
builtins.getAttr directory attrs == "set")
|
||||||
|
directories);
|
||||||
|
}
|
Loading…
Reference in a new issue