Simplify build systems

This commit is contained in:
DashieTM 2024-09-08 19:09:35 +02:00
parent b994e4698c
commit 9535108bb7
6 changed files with 94 additions and 131 deletions

3
.gitignore vendored
View file

@ -1 +1,2 @@
result/ result/*
result

View file

@ -1,12 +1,8 @@
# with friendly help by stylix: https://github.com/danth/stylix/blob/master/docs/default.nix # with friendly help by stylix: https://github.com/danth/stylix/blob/master/docs/default.nix
{ { pkgs, build_systems, lib, ... }:
pkgs,
build_systems,
lib,
...
}:
let let
makeOptionsDoc = configuration: pkgs.nixosOptionsDoc { options = configuration; }; makeOptionsDoc = configuration:
pkgs.nixosOptionsDoc { options = configuration; };
generateDocs = obj: '' generateDocs = obj: ''
touch src/${obj.fst}.md touch src/${obj.fst}.md
sed '/*Declared by:*/,/^$/d' <${obj.snd.optionsCommonMark} >> src/${obj.fst}.md sed '/*Declared by:*/,/^$/d' <${obj.snd.optionsCommonMark} >> src/${obj.fst}.md
@ -15,17 +11,18 @@ let
echo "- [${name}](${name}.md)" >> src/SUMMARY.md echo "- [${name}](${name}.md)" >> src/SUMMARY.md
''; '';
system = (build_systems ../example/.)."example".options; system = (build_systems ../example/.)."example".options;
makeOptionsDocPrograms = name: pkgs.nixosOptionsDoc { options = system.mods.${name}; }; makeOptionsDocPrograms = name:
pkgs.nixosOptionsDoc { options = system.mods.${name}; };
conf = makeOptionsDoc system.conf; conf = makeOptionsDoc system.conf;
paths = builtins.readDir ../modules/programs; paths = builtins.readDir ../modules/programs;
names = lib.lists.remove "default" ( names = lib.lists.remove "default"
map (name: lib.strings.removeSuffix ".nix" name) (lib.attrsets.mapAttrsToList (name: _: name) paths) (map (name: lib.strings.removeSuffix ".nix" name)
); (lib.attrsets.mapAttrsToList (name: _: name) paths));
mods = map makeOptionsDocPrograms names; mods = map makeOptionsDocPrograms names;
docs = lib.strings.concatLines (map generateDocs (lib.lists.zipLists names mods)); docs =
lib.strings.concatLines (map generateDocs (lib.lists.zipLists names mods));
summary = lib.strings.concatStringsSep " " (map summaryAppend names); summary = lib.strings.concatStringsSep " " (map summaryAppend names);
in in pkgs.stdenvNoCC.mkDerivation {
pkgs.stdenvNoCC.mkDerivation {
name = "dashNix-book"; name = "dashNix-book";
src = ./.; src = ./.;

View file

@ -26,11 +26,13 @@ dashNix = {
You can then configure your systems in your flake outputs with a provided library command: You can then configure your systems in your flake outputs with a provided library command:
```nix ```nix
nixosConfigurations = (inputs.dashNix.dashNixLib.build_systems ./.); nixosConfigurations = inputs.dashNix.dashNixLib.build_systems ./.;
``` ```
The paremeter specifies where your hosts directory will be placed, in said directory you can then create a directory for each system. This command will build each system that is placed within the hosts/ directory.
Note, the name of the systems directory is also its hostname. In this directory create one directory for each system you want to configure with DashNix.
This will automatically pick up the hostname for the system and look for 3 different files that are explained below.
(Optionally, you can also change the parameter root (./.) to define a different starting directory than hosts/)
In order for your configuration to work, you are required to at least provide a single config file with a further config file being optional for custom configuration. In order for your configuration to work, you are required to at least provide a single config file with a further config file being optional for custom configuration.
The hardware.nix specifies additional NixOS configuration, while home.nix specifies additional home-manager configuration. (both optional) The hardware.nix specifies additional NixOS configuration, while home.nix specifies additional home-manager configuration. (both optional)

View file

@ -4,7 +4,8 @@
inputs = { inputs = {
dashvim.url = "github:DashieTM/DashVim"; dashvim.url = "github:DashieTM/DashVim";
hyprland.url = "git+https://github.com/hyprwm/Hyprland?submodules=1"; hyprland.url = "git+https://github.com/hyprwm/Hyprland?submodules=1";
ironbar.url = "github:JakeStanger/ironbar?ref=3a1c60442382f970cdb7669814b6ef3594d9f048"; ironbar.url =
"github:JakeStanger/ironbar?ref=3a1c60442382f970cdb7669814b6ef3594d9f048";
anyrun.url = "github:Kirottu/anyrun"; anyrun.url = "github:Kirottu/anyrun";
nixpkgs.url = "github:NixOs/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOs/nixpkgs/nixos-unstable";
stable.url = "github:NixOs/nixpkgs/nixos-24.05"; stable.url = "github:NixOs/nixpkgs/nixos-24.05";
@ -21,11 +22,9 @@
}; };
}; };
outputs = outputs = { ... }@inputs: {
{ ... }@inputs: nixosConfigurations = inputs.dashNix.dashNixLib.build_systems ./.;
{ };
nixosConfigurations = (inputs.dashNix.dashNixLib.build_systems ./.);
};
nixConfig = { nixConfig = {
builders-use-substitutes = true; builders-use-substitutes = true;

View file

@ -5,9 +5,7 @@
nixpkgs.url = "github:NixOs/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOs/nixpkgs/nixos-unstable";
stable.url = "github:NixOs/nixpkgs/nixos-24.05"; stable.url = "github:NixOs/nixpkgs/nixos-24.05";
nix-flatpak = { nix-flatpak = { url = "github:gmodena/nix-flatpak"; };
url = "github:gmodena/nix-flatpak";
};
home-manager = { home-manager = {
url = "github:nix-community/home-manager"; url = "github:nix-community/home-manager";
@ -25,7 +23,8 @@
hyprland.url = "git+https://github.com/hyprwm/Hyprland?submodules=1"; hyprland.url = "git+https://github.com/hyprwm/Hyprland?submodules=1";
ironbar = { ironbar = {
url = "github:JakeStanger/ironbar?ref=3a1c60442382f970cdb7669814b6ef3594d9f048"; url =
"github:JakeStanger/ironbar?ref=3a1c60442382f970cdb7669814b6ef3594d9f048";
}; };
stylix.url = "github:danth/stylix"; stylix.url = "github:danth/stylix";
@ -48,14 +47,11 @@
}; };
}; };
outputs = outputs = { self, ... }@inputs:
{ self, ... }@inputs:
let let
stable = import inputs.stable { stable = import inputs.stable {
system = "x86_64-linux"; system = "x86_64-linux";
config = { config = { allowUnfree = true; };
allowUnfree = true;
};
}; };
pkgs = import inputs.nixpkgs { pkgs = import inputs.nixpkgs {
system = "x86_64-linux"; system = "x86_64-linux";
@ -65,8 +61,7 @@
allowUnfree = true; allowUnfree = true;
}; };
}; };
in in rec {
rec {
dashNixLib = import ./lib { dashNixLib = import ./lib {
inherit self inputs pkgs; inherit self inputs pkgs;
lib = inputs.nixpkgs.lib; lib = inputs.nixpkgs.lib;

View file

@ -1,60 +1,51 @@
{ { inputs, pkgs, self, lib, additionalMods ? {
inputs, nixos = [ ];
pkgs, home = [ ];
self, }, mods ? {
lib, nixos = [
additionalMods ? { inputs.home-manager.nixosModules.home-manager
nixos = [ ]; inputs.stylix.nixosModules.stylix
home = [ ]; ../base
}, ../home
mods ? { ../modules
nixos = [ ];
inputs.home-manager.nixosModules.home-manager home = [
inputs.stylix.nixosModules.stylix inputs.anyrun.homeManagerModules.default
../base inputs.ironbar.homeManagerModules.default
../home inputs.oxicalc.homeManagerModules.default
../modules inputs.oxishut.homeManagerModules.default
]; inputs.oxinoti.homeManagerModules.default
home = [ inputs.oxidash.homeManagerModules.default
inputs.anyrun.homeManagerModules.default inputs.oxipaste.homeManagerModules.default
inputs.ironbar.homeManagerModules.default inputs.hyprdock.homeManagerModules.default
inputs.oxicalc.homeManagerModules.default inputs.hyprland.homeManagerModules.default
inputs.oxishut.homeManagerModules.default inputs.reset.homeManagerModules.default
inputs.oxinoti.homeManagerModules.default inputs.nix-flatpak.homeManagerModules.nix-flatpak
inputs.oxidash.homeManagerModules.default inputs.sops-nix.homeManagerModules.sops
inputs.oxipaste.homeManagerModules.default inputs.dashvim.homeManagerModules.dashvim
inputs.hyprdock.homeManagerModules.default ../modules
inputs.hyprland.homeManagerModules.default ];
inputs.reset.homeManagerModules.default }, ... }: {
inputs.nix-flatpak.homeManagerModules.nix-flatpak /* *
inputs.sops-nix.homeManagerModules.sops # build_systems
inputs.dashvim.homeManagerModules.dashvim
../modules
];
},
...
}:
{
/**
# build_systems
Builds system given a list of system names which are placed within your hosts/ directory. Note that each system has its own directory in hosts/ as well. Builds system given a list of system names which are placed within your hosts/ directory. Note that each system has its own directory in hosts/ as well.
A minimal configuration requires the file configuration.nix within each system directory, this will be the base config that is used across both NisOS and home-manager, specific optional files can also be added, hardware.nix for NisOS configuration and home.nix for home-manager configuration. A minimal configuration requires the file configuration.nix within each system directory, this will be the base config that is used across both NisOS and home-manager, specific optional files can also be added, hardware.nix for NisOS configuration and home.nix for home-manager configuration.
The second parameter is the root of your configuration, which should be ./. in most cases. The second parameter is the root of your configuration, which should be ./. in most cases.
`root` `root`
: the root path of your configuration : the root path of your configuration
# Example usage # Example usage
:::{.example} :::{.example}
```nix ```nix
nixosConfigurations = nixosConfigurations =
(build_systems [ "nixos" ] ./.); (build_systems [ "nixos" ] ./.);
``` ```
::: :::
*/ */
# let # let
# paths = builtins.readDir ; # paths = builtins.readDir ;
@ -63,53 +54,31 @@
# ); # );
# in # in
build_systems = build_systems = root:
root: builtins.listToAttrs (map (name: {
builtins.listToAttrs ( name = name;
map value = let
(name: { mod = root + /hosts/${name}/configuration.nix;
name = name; additionalNixosConfig = root + /hosts/${name}/hardware.nix;
value = additionalHomeConfig = root + /hosts/${name}/home.nix;
let in inputs.nixpkgs.lib.nixosSystem {
mod = root + /hosts/${name}/configuration.nix; specialArgs = {
additionalNixosConfig = root + /hosts/${name}/hardware.nix; inherit self inputs pkgs mod additionalHomeConfig root;
additionalHomeConfig = root + /hosts/${name}/home.nix; hostName = name;
in homeMods = mods.home;
inputs.nixpkgs.lib.nixosSystem { additionalHomeMods = additionalMods.home;
specialArgs = { };
inherit modules = [ mod ] ++ mods.nixos ++ additionalMods.nixos
self ++ inputs.nixpkgs.lib.optional
inputs (builtins.pathExists additionalNixosConfig) additionalNixosConfig
pkgs ++ inputs.nixpkgs.lib.optional (builtins.pathExists mod) mod;
mod };
additionalHomeConfig }) (lib.lists.remove "" (lib.attrsets.mapAttrsToList
root (name: fType: if fType == "directory" then name else "")
; (builtins.readDir (root + /hosts)))));
hostName = name;
homeMods = mods.home;
additionalHomeMods = additionalMods.home;
};
modules =
[ mod ]
++ mods.nixos
++ additionalMods.nixos
++ inputs.nixpkgs.lib.optional (builtins.pathExists additionalNixosConfig) additionalNixosConfig
++ inputs.nixpkgs.lib.optional (builtins.pathExists mod) mod;
};
})
(
lib.lists.remove "" (
lib.attrsets.mapAttrsToList (name: fType: if fType == "directory" then name else "") (
builtins.readDir (root + /hosts)
)
)
)
);
buildIso = inputs.nixpkgs.lib.nixosSystem { buildIso = inputs.nixpkgs.lib.nixosSystem {
specialArgs = { specialArgs = { inherit self inputs pkgs; };
inherit self inputs pkgs;
};
modules = [ ../iso/configuration.nix ]; modules = [ ../iso/configuration.nix ];
}; };
} }