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
{
pkgs,
build_systems,
lib,
...
}:
{ pkgs, build_systems, lib, ... }:
let
makeOptionsDoc = configuration: pkgs.nixosOptionsDoc { options = configuration; };
makeOptionsDoc = configuration:
pkgs.nixosOptionsDoc { options = configuration; };
generateDocs = obj: ''
touch 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
'';
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;
paths = builtins.readDir ../modules/programs;
names = lib.lists.remove "default" (
map (name: lib.strings.removeSuffix ".nix" name) (lib.attrsets.mapAttrsToList (name: _: name) paths)
);
names = lib.lists.remove "default"
(map (name: lib.strings.removeSuffix ".nix" name)
(lib.attrsets.mapAttrsToList (name: _: name) paths));
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);
in
pkgs.stdenvNoCC.mkDerivation {
in pkgs.stdenvNoCC.mkDerivation {
name = "dashNix-book";
src = ./.;

View file

@ -26,11 +26,13 @@ dashNix = {
You can then configure your systems in your flake outputs with a provided library command:
```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.
Note, the name of the systems directory is also its hostname.
This command will build each system that is placed within the hosts/ directory.
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.
The hardware.nix specifies additional NixOS configuration, while home.nix specifies additional home-manager configuration. (both optional)

View file

@ -4,7 +4,8 @@
inputs = {
dashvim.url = "github:DashieTM/DashVim";
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";
nixpkgs.url = "github:NixOs/nixpkgs/nixos-unstable";
stable.url = "github:NixOs/nixpkgs/nixos-24.05";
@ -21,10 +22,8 @@
};
};
outputs =
{ ... }@inputs:
{
nixosConfigurations = (inputs.dashNix.dashNixLib.build_systems ./.);
outputs = { ... }@inputs: {
nixosConfigurations = inputs.dashNix.dashNixLib.build_systems ./.;
};
nixConfig = {

View file

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

View file

@ -1,13 +1,7 @@
{
inputs,
pkgs,
self,
lib,
additionalMods ? {
{ inputs, pkgs, self, lib, additionalMods ? {
nixos = [ ];
home = [ ];
},
mods ? {
}, mods ? {
nixos = [
inputs.home-manager.nixosModules.home-manager
inputs.stylix.nixosModules.stylix
@ -31,11 +25,8 @@
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.
@ -63,53 +54,31 @@
# );
# in
build_systems =
root:
builtins.listToAttrs (
map
(name: {
build_systems = root:
builtins.listToAttrs (map (name: {
name = name;
value =
let
value = let
mod = root + /hosts/${name}/configuration.nix;
additionalNixosConfig = root + /hosts/${name}/hardware.nix;
additionalHomeConfig = root + /hosts/${name}/home.nix;
in
inputs.nixpkgs.lib.nixosSystem {
in inputs.nixpkgs.lib.nixosSystem {
specialArgs = {
inherit
self
inputs
pkgs
mod
additionalHomeConfig
root
;
inherit self inputs pkgs mod additionalHomeConfig root;
hostName = name;
homeMods = mods.home;
additionalHomeMods = additionalMods.home;
};
modules =
[ mod ]
++ mods.nixos
++ additionalMods.nixos
++ inputs.nixpkgs.lib.optional (builtins.pathExists additionalNixosConfig) additionalNixosConfig
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)
)
)
)
);
}) (lib.lists.remove "" (lib.attrsets.mapAttrsToList
(name: fType: if fType == "directory" then name else "")
(builtins.readDir (root + /hosts)))));
buildIso = inputs.nixpkgs.lib.nixosSystem {
specialArgs = {
inherit self inputs pkgs;
};
specialArgs = { inherit self inputs pkgs; };
modules = [ ../iso/configuration.nix ];
};
}