Compare commits

..

No commits in common. "5a3edc7ff09d6ded49ea8bcec0f9f20c0eef9cd6" and "d1d748594299cc8890ca0f30261a2e31bbf88188" have entirely different histories.

19 changed files with 172 additions and 363 deletions

View file

@ -1,6 +1,3 @@
{ ... }@flake: { ... }@flake: { ... }@inputs: { ... }@imports: {
{ ... }@inputs: imports = builtins.attrValues (flake.hmModules or {});
{ ... }@imports:
{
imports = builtins.attrValues (flake.hmModules or { });
} }

View file

@ -1,8 +1,4 @@
flake: flake: { ... }@inputs: { ... }@imports: let
{ ... }@inputs:
{ ... }@imports:
let
module' = name: imports: builtins.trace "user module: ${name}" { inherit imports; }; module' = name: imports: builtins.trace "user module: ${name}" { inherit imports; };
modules = builtins.mapAttrs module' imports."user/module"; modules = builtins.mapAttrs module' imports."user/module";
in in { default = module' "default" (builtins.attrValues modules); } // modules
{ default = module' "default" (builtins.attrValues modules); } // modules

View file

@ -1,7 +1,4 @@
{ ... }@flake: { ... }@flake: { ... }@inputs: { profile, ... }@imports: let
{ ... }@inputs:
{ profile, ... }@imports:
let
profile' = name: snippets: builtins.trace "home-manager: profile: ${name}" { imports = snippets; }; profile' = name: snippets: builtins.trace "home-manager: profile: ${name}" { imports = snippets; };
in in builtins.mapAttrs profile' profile
builtins.mapAttrs profile' profile

View file

@ -1,30 +1,15 @@
{ { nixosUsers ? {}, nixosGroups ? {}, nixosModules, hmModules ? { default = {}; }, ...}@flake: { ... }@inputs: { host, ... }@imports: let
nixosUsers ? { }, host' = name: snippets: let
nixosGroups ? { },
nixosModules,
hmModules ? {
default = { };
},
...
}@flake:
{ ... }@inputs:
{ host, ... }@imports:
let
host' =
name: snippets:
let
overlay = self: super: { overlay = self: super: {
makeModulesClosure = x: super.makeModulesClosure (x // { allowMissing = true; }); makeModulesClosure = x: super.makeModulesClosure (x // { allowMissing = true; });
}; };
common = common = { modulesPath, lib, ... }: {
{ modulesPath, lib, ... }:
{
config.nixpkgs.overlays = [ overlay ]; config.nixpkgs.overlays = [ overlay ];
config.networking.hostName = lib.mkForce name; config.networking.hostName = lib.mkForce name;
config.home-manager = { config.home-manager = {
sharedModules = [ hmModules.default ]; sharedModules = [ hmModules.default ] ;
}; };
imports = [ imports = [
@ -36,15 +21,12 @@ let
system = inputs.nixpkgs.lib.nixosSystem { system = inputs.nixpkgs.lib.nixosSystem {
specialArgs = { inherit inputs flake; }; specialArgs = { inherit inputs flake; };
modules = [ modules = [ common ]
common
]
++ snippets ++ snippets
++ builtins.attrValues nixosUsers ++ builtins.attrValues nixosUsers
++ builtins.attrValues nixosGroups; ++ builtins.attrValues nixosGroups
;
}; };
in in system.config.system.build.isoImage;
system.config.system.build.isoImage;
in in builtins.mapAttrs host' host
builtins.mapAttrs host' host

View file

@ -1,45 +1,19 @@
{ { nixosUsers ? {}, nixosGroups ? {}, nixosModules, hmModules ? { default = {}; }, ...}@flake: { ... }@inputs: { host, ... }@imports: let
nixosUsers ? { }, host' = name: snippets: let
nixosGroups ? { }, system = { namespace?"fbs42", nixpkgs?"nixpkgs" }: inputs.${nixpkgs}.lib.nixosSystem {
nixosModules,
hmModules ? {
default = { };
},
...
}@flake:
{ ... }@inputs:
{ host, ... }@imports:
let
host' =
name: snippets:
let
system =
{
namespace ? "fbs42",
nixpkgs ? "nixpkgs",
}:
inputs.${nixpkgs}.lib.nixosSystem {
specialArgs = { inherit inputs flake namespace; }; specialArgs = { inherit inputs flake namespace; };
modules = modules = builtins.concatLists (map (base: builtins.attrValues (flake.lib.scan { base = "${base}/host/${name}"; })) flake.lib.schema.base)
builtins.concatLists (
map (
base: builtins.attrValues (flake.lib.scan { base = "${base}/host/${name}"; })
) flake.lib.schema.base
)
++ [ { config.networking.hostName = name; } ] ++ [ { config.networking.hostName = name; } ]
++ [ nixosModules.default ] ++ [ nixosModules.default ]
++ [ inputs.home-manager.nixosModules.default ] ++ [ inputs.home-manager.nixosModules.default ]
++ [ { config.home-manager.sharedModules = [ hmModules.default ]; } ] ++ [ { config.home-manager.sharedModules = [ hmModules.default ]; } ]
++ [ { config.home-manager.extraSpecialArgs = { inherit flake namespace; }; } ] ++ [ { config.home-manager.extraSpecialArgs = { inherit flake namespace; }; } ]
++ builtins.attrValues nixosUsers ++ builtins.attrValues nixosUsers
++ builtins.attrValues nixosGroups; ++ builtins.attrValues nixosGroups
;
}; };
cfg = cfg = assert builtins.length snippets == 1; builtins.head snippets;
assert builtins.length snippets == 1; in system cfg;
builtins.head snippets;
in
system cfg;
in in builtins.mapAttrs host' host
builtins.mapAttrs host' host

View file

@ -1,25 +1,10 @@
flake: flake: { ... }@inputs: { group, ... }@imports: let
{ ... }@inputs: group' = name: snippets: { pkgs, lib, options, config, ... }@args: let
{ group, ... }@imports:
let
group' =
name: snippets:
{
pkgs,
lib,
options,
config,
...
}@args:
let
invoke = x: if builtins.isFunction x then x args else x; invoke = x: if builtins.isFunction x then x args else x;
in in {
{
options.fbs42.group.${name} = lib.mkEnableOption name; options.fbs42.group.${name} = lib.mkEnableOption name;
config.users.groups.${name} = lib.mkIf ( config.users.groups.${name} = lib.mkIf
config.fbs42.group.${name} (config.fbs42.group.${name} || builtins.any (usr: usr.group == name) (builtins.attrValues config.users.users))
|| builtins.any (usr: usr.group == name) (builtins.attrValues config.users.users) (lib.mkMerge (map invoke snippets));
) (lib.mkMerge (map invoke snippets));
}; };
in in builtins.mapAttrs group' group
builtins.mapAttrs group' group

View file

@ -1,14 +1,3 @@
flake: flake: { ... }@inputs: { module, ... }@imports: let
{ ... }@inputs: modules = builtins.mapAttrs (name: imports: builtins.trace "module: ${name}" { inherit imports; }) module;
{ module, ... }@imports: in { default = { imports = builtins.attrValues modules; }; } // modules
let
modules = builtins.mapAttrs (
name: imports: builtins.trace "module: ${name}" { inherit imports; }
) module;
in
{
default = {
imports = builtins.attrValues modules;
};
}
// modules

View file

@ -1,4 +1,2 @@
{ ... }@flake: { ... }@flake: { ... }@inputs: { profile, ... }@imports:
{ ... }@inputs: builtins.mapAttrs (name: imports: builtins.trace "profile: ${name}" { inherit imports; }) profile
{ profile, ... }@imports:
builtins.mapAttrs (name: imports: builtins.trace "profile: ${name}" { inherit imports; }) profile

View file

@ -1,15 +1,5 @@
self: self: { ... }@inputs: { user, ... }@imports: let
{ ... }@inputs: user' = name: snippets: { pkgs, lib, config, ... }@args:
{ user, ... }@imports:
let
user' =
name: snippets:
{
pkgs,
lib,
config,
...
}@args:
builtins.trace "user: ${name}" { builtins.trace "user: ${name}" {
options.fbs42.user.${name} = lib.mkEnableOption name; options.fbs42.user.${name} = lib.mkEnableOption name;
## no longer with nixos-24.11 ## no longer with nixos-24.11
@ -17,15 +7,11 @@ let
# group = lib.mkDefault name; # group = lib.mkDefault name;
#}; #};
imports = map ( imports = map ({ user, home-manager}: {
{ user, home-manager }:
{
config = lib.mkIf config.fbs42.user.${name} { config = lib.mkIf config.fbs42.user.${name} {
users.users.${name} = (user args); users.users.${name} = (user args);
home-manager.users.${name} = home-manager; home-manager.users.${name} = home-manager;
}; };
} }) snippets;
) snippets;
}; };
in in builtins.mapAttrs user' user
builtins.mapAttrs user' user

View file

@ -1,30 +1,15 @@
{ { nixosUsers ? {}, nixosGroups ? {}, nixosModules, hmModules ? { default = {}; }, ...}@flake: { ... }@inputs: { host, ... }@imports: let
nixosUsers ? { }, host' = name: snippets: let
nixosGroups ? { },
nixosModules,
hmModules ? {
default = { };
},
...
}@flake:
{ ... }@inputs:
{ host, ... }@imports:
let
host' =
name: snippets:
let
overlay = self: super: { overlay = self: super: {
makeModulesClosure = x: super.makeModulesClosure (x // { allowMissing = true; }); makeModulesClosure = x: super.makeModulesClosure (x // { allowMissing = true; });
}; };
common = common = { modulesPath, lib, ... }: {
{ modulesPath, lib, ... }:
{
config.nixpkgs.overlays = [ overlay ]; config.nixpkgs.overlays = [ overlay ];
config.networking.hostName = lib.mkForce name; config.networking.hostName = lib.mkForce name;
config.home-manager = { config.home-manager = {
sharedModules = [ hmModules.default ]; sharedModules = [ hmModules.default ] ;
}; };
imports = [ imports = [
@ -38,15 +23,12 @@ let
system = inputs.nixpkgs.lib.nixosSystem { system = inputs.nixpkgs.lib.nixosSystem {
specialArgs = { inherit inputs flake; }; specialArgs = { inherit inputs flake; };
modules = [ modules = [ common ]
common
]
++ snippets ++ snippets
++ builtins.attrValues nixosUsers ++ builtins.attrValues nixosUsers
++ builtins.attrValues nixosGroups; ++ builtins.attrValues nixosGroups
;
}; };
in in system.config.system.build.sdImage;
system.config.system.build.sdImage;
in in builtins.mapAttrs host' host
builtins.mapAttrs host' host

16
flake.lock generated
View file

@ -22,32 +22,32 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1757808926, "lastModified": 1747688870,
"narHash": "sha256-K6PEI5PYY94TVMH0mX3MbZNYFme7oNRKml/85BpRRAo=", "narHash": "sha256-ypL9WAZfmJr5V70jEVzqGjjQzF0uCkz+AFQF7n9NmNc=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "f21d9167782c086a33ad53e2311854a8f13c281e", "rev": "d5f1f641b289553927b3801580598d200a501863",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nix-community", "owner": "nix-community",
"ref": "release-25.05", "ref": "release-24.11",
"repo": "home-manager", "repo": "home-manager",
"type": "github" "type": "github"
} }
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1757810152, "lastModified": 1751274312,
"narHash": "sha256-Vp9K5ol6h0J90jG7Rm4RWZsCB3x7v5VPx588TQ1dkfs=", "narHash": "sha256-/bVBlRpECLVzjV19t5KMdMFWSwKLtb5RyXdjz3LJT+g=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "9a094440e02a699be5c57453a092a8baf569bdad", "rev": "50ab793786d9de88ee30ec4e4c24fb4236fc2674",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nixos", "owner": "nixos",
"ref": "nixos-25.05", "ref": "nixos-24.11",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }

View file

@ -1,9 +1,9 @@
{ {
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05"; nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
hardware.url = "github:nixos/nixos-hardware"; hardware.url = "github:nixos/nixos-hardware";
home-manager = { home-manager = {
url = "github:nix-community/home-manager/release-25.05"; url = "github:nix-community/home-manager/release-24.11";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
}; };

View file

@ -1 +1 @@
{ } {}

View file

@ -1,34 +1,21 @@
let let
function = function = name: value: let
name: value: result = if builtins.isAttrs value then {...}: value else value;
let
result = if builtins.isAttrs value then { ... }: value else value;
result' = builtins.trace "result ${name}=${builtins.typeOf result}" result; result' = builtins.trace "result ${name}=${builtins.typeOf result}" result;
in in
assert builtins.isFunction result'; assert builtins.isFunction result';
result; result;
config = config = { user?{}, home-manager?{} }@set:
{
user ? { },
home-manager ? { },
}@set:
builtins.mapAttrs function { inherit user home-manager; }; builtins.mapAttrs function { inherit user home-manager; };
in in name: value: let
name: value: result = if builtins.isFunction value
let then
result =
if builtins.isFunction value then
config { user = value; } config { user = value; }
else if else if builtins.any (attr: builtins.hasAttr attr value) [ "user" "home-manager" ]
builtins.any (attr: builtins.hasAttr attr value) [
"user"
"home-manager"
]
then then
config value config value
else else
config { user = value; }; config { user = value; };
in in result
result

View file

@ -1 +1,2 @@
name: profile: profile name: profile: profile

View file

@ -1,81 +1,34 @@
let let
scan = import ./scan.nix; scan = import ./scan.nix;
flake' = flake' = self: { imports, exports , base }@schema: { ... }@inputs: { ... }@imports: let
self:
{
imports,
exports,
base,
}@schema:
{ ... }@inputs:
{ ... }@imports:
let
lib = { lib = {
inherit inherit scan schema inputs imports;
scan
schema
inputs
imports
;
extend = flake schema inputs imports; extend = flake schema inputs imports;
new = flake { } { } { }; new = flake {} {} {};
# TODO: override # TODO: override
}; };
convert = attr: value: value self inputs imports; convert = attr: value: value self inputs imports;
result = (builtins.mapAttrs convert schema.exports); result = (builtins.mapAttrs convert schema.exports);
in in result // { lib = lib // (result.lib or {}); };
{
formatter = builtins.mapAttrs (_: pkgs: pkgs.nixfmt-tree) inputs.nixpkgs.legacyPackages;
}
// result
// {
lib = lib // (result.lib or { });
};
flake = flake = { imports?{}, exports?{}, base?[] }@schema'old: { ... }@inputs'old: { ... }@imports'old: { ... }@inputs'new: base: let
{
imports ? { },
exports ? { },
base ? [ ],
}@schema'old:
{ ... }@inputs'old:
{ ... }@imports'old:
{ ... }@inputs'new:
base:
let
schema = { schema = {
imports = imports = (schema'old.imports or {}) // scan { base = base + "/import"; recursive = true; };
(schema'old.imports or { }) exports = (schema'old.exports or {}) // scan { base = base + "/export"; };
// scan { base = [ base ] ++ (schema'old.base or []);
base = base + "/import";
recursive = true;
};
exports = (schema'old.exports or { }) // scan { base = base + "/export"; };
base = [ base ] ++ (schema'old.base or [ ]);
}; };
merge = merge = attr: let
attr: old = imports'old.${attr} or {};
let new = imports'new.${attr} or {};
old = imports'old.${attr} or { }; in builtins.mapAttrs (attr: _: (old.${attr} or []) ++ (new.${attr} or [])) (old//new);
new = imports'new.${attr} or { };
in
builtins.mapAttrs (attr: _: (old.${attr} or [ ]) ++ (new.${attr} or [ ])) (old // new);
imports'new = builtins.mapAttrs ( imports'new = builtins.mapAttrs (name: value: scan { base = base + "/${name}"; convert = name: content: [ (value name content) ]; }) schema.imports;
name: value: result = flake' result schema
scan { (inputs'old // (builtins.removeAttrs inputs'new ["self"]))
base = base + "/${name}"; (builtins.mapAttrs (attr: _: merge attr) schema.imports);
convert = name: content: [ (value name content) ]; in result;
}
) schema.imports;
result = flake' result schema (inputs'old // (builtins.removeAttrs inputs'new [ "self" ])) (
builtins.mapAttrs (attr: _: merge attr) schema.imports
);
in
result;
in in flake {} {} {}
flake { } { } { }

1
lib/host.nix Normal file
View file

@ -0,0 +1 @@
self:

View file

@ -1,42 +1,23 @@
{ { base, convert ? name: value: value, recursive ? false }:
base,
convert ? name: value: value,
recursive ? false,
}:
let let
scan = scan = sub: let
sub:
let
all = builtins.readDir (base + "/${builtins.concatStringsSep "/" sub}"); all = builtins.readDir (base + "/${builtins.concatStringsSep "/" sub}");
names = filter: builtins.filter filter (builtins.attrNames all); names = filter: builtins.filter filter (builtins.attrNames all);
nix = nix = name: all.${name} == "regular" && builtins.stringLength name > 4 && builtins.substring (builtins.stringLength name - 4) 4 name == ".nix";
name:
all.${name} == "regular"
&& builtins.stringLength name > 4
&& builtins.substring (builtins.stringLength name - 4) 4 name == ".nix";
dir = name: all.${name} == "directory"; dir = name: all.${name} == "directory";
files = map (name: sub ++ [ (builtins.substring 0 (builtins.stringLength name - 4) name) ]) ( files = map (name: sub ++ [ (builtins.substring 0 (builtins.stringLength name - 4) name) ]) (names nix);
names nix dirs = builtins.concatLists (map (name: scan (sub ++ [name])) (names dir));
); in if recursive then files ++ dirs else files;
dirs = builtins.concatLists (map (name: scan (sub ++ [ name ])) (names dir));
in
if recursive then files ++ dirs else files;
root = scan [ ]; root = scan [];
item = item = relative: let
relative:
let
name = builtins.concatStringsSep "/" relative; name = builtins.concatStringsSep "/" relative;
absolute = base + "/${name}.nix"; absolute = base + "/${name}.nix";
content = import absolute; content = import absolute;
value = convert name content; value = convert name content;
in in { inherit name value; };
{
inherit name value;
};
items = map item root; items = map item root;
in in if builtins.pathExists base then builtins.listToAttrs (map item root) else {}
if builtins.pathExists base then builtins.listToAttrs (map item root) else { }

View file

@ -1 +1 @@
{ } {}