initial commit
This commit is contained in:
commit
5679c003d8
26 changed files with 296 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
*
|
||||||
|
!*/
|
||||||
|
!*.nix
|
||||||
3
export/hmModule.nix
Normal file
3
export/hmModule.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
{ ... }@flake: { ... }@inputs: { ... }@imports: {
|
||||||
|
imports = builtins.attrValues (flake.hmModules or {});
|
||||||
|
}
|
||||||
4
export/hmModules.nix
Normal file
4
export/hmModules.nix
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
flake: { ... }@inputs: { ... }@imports: let
|
||||||
|
module' = name: imports: builtins.trace "user module: ${name}" { inherit imports; };
|
||||||
|
modules = builtins.mapAttrs module' imports."user/module";
|
||||||
|
in { default = module' "default" (builtins.attrValues modules); } // modules
|
||||||
4
export/hmProfiles.nix
Normal file
4
export/hmProfiles.nix
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
{ ... }@flake: { ... }@inputs: { profile, ... }@imports: let
|
||||||
|
profile' = name: snippets: builtins.trace "home-manager: profile: ${name}" { imports = snippets; };
|
||||||
|
in builtins.mapAttrs profile' profile
|
||||||
|
|
||||||
32
export/iso.nix
Normal file
32
export/iso.nix
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
{ nixosUsers ? {}, nixosGroups ? {}, nixosModules, hmModules ? { default = {}; }, ...}@flake: { ... }@inputs: { host, ... }@imports: let
|
||||||
|
host' = name: snippets: let
|
||||||
|
|
||||||
|
overlay = self: super: {
|
||||||
|
makeModulesClosure = x: super.makeModulesClosure (x // { allowMissing = true; });
|
||||||
|
};
|
||||||
|
|
||||||
|
common = { modulesPath, lib, ... }: {
|
||||||
|
config.nixpkgs.overlays = [ overlay ];
|
||||||
|
config.networking.hostName = lib.mkForce name;
|
||||||
|
config.home-manager = {
|
||||||
|
sharedModules = [ hmModules.default ] ;
|
||||||
|
};
|
||||||
|
|
||||||
|
imports = [
|
||||||
|
(modulesPath + "/installer/cd-dvd/installation-cd-minimal-new-kernel-no-zfs.nix")
|
||||||
|
nixosModules.default
|
||||||
|
inputs.home-manager.nixosModules.default
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
system = inputs.nixpkgs.lib.nixosSystem {
|
||||||
|
specialArgs = { inherit inputs flake; };
|
||||||
|
modules = [ common ]
|
||||||
|
++ snippets
|
||||||
|
++ builtins.attrValues nixosUsers
|
||||||
|
++ builtins.attrValues nixosGroups
|
||||||
|
;
|
||||||
|
};
|
||||||
|
in system.config.system.build.isoImage;
|
||||||
|
|
||||||
|
in builtins.mapAttrs host' host
|
||||||
18
export/nixosConfigurations.nix
Normal file
18
export/nixosConfigurations.nix
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
{ nixosUsers ? {}, nixosGroups ? {}, 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 = if builtins.isList namespace then namespace else [ namespace ]; };
|
||||||
|
modules = builtins.concatLists (map (base: builtins.attrValues (flake.lib.scan { base = "${base}/host/${name}"; })) flake.lib.schema.base)
|
||||||
|
++ [ { config.networking.hostName = name; } ]
|
||||||
|
++ [ nixosModules.default ]
|
||||||
|
++ [ inputs.home-manager.nixosModules.default ]
|
||||||
|
++ [ { config.home-manager.sharedModules = [ hmModules.default ]; } ]
|
||||||
|
++ builtins.attrValues nixosUsers
|
||||||
|
++ builtins.attrValues nixosGroups
|
||||||
|
;
|
||||||
|
};
|
||||||
|
|
||||||
|
cfg = assert builtins.length snippets == 1; builtins.head snippets;
|
||||||
|
in system cfg;
|
||||||
|
|
||||||
|
in builtins.mapAttrs host' host
|
||||||
10
export/nixosGroup.nix
Normal file
10
export/nixosGroup.nix
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
flake: { ... }@inputs: { group, ... }@imports: let
|
||||||
|
group' = name: snippets: { pkgs, lib, options, config, ... }@args: let
|
||||||
|
invoke = x: if builtins.isFunction x then x args else x;
|
||||||
|
in {
|
||||||
|
options.fbs42.group.${name} = lib.mkEnableOption name;
|
||||||
|
config.users.groups.${name} = lib.mkIf
|
||||||
|
(config.fbs42.group.${name} || builtins.any (usr: usr.group == name) (builtins.attrValues config.users.users))
|
||||||
|
(lib.mkMerge (map invoke snippets));
|
||||||
|
};
|
||||||
|
in builtins.mapAttrs group' group
|
||||||
3
export/nixosModules.nix
Normal file
3
export/nixosModules.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
flake: { ... }@inputs: { module, ... }@imports: let
|
||||||
|
modules = builtins.mapAttrs (name: imports: builtins.trace "module: ${name}" { inherit imports; }) module;
|
||||||
|
in { default = { imports = builtins.attrValues modules; }; } // modules
|
||||||
2
export/nixosProfiles.nix
Normal file
2
export/nixosProfiles.nix
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
{ ... }@flake: { ... }@inputs: { profile, ... }@imports:
|
||||||
|
builtins.mapAttrs (name: imports: builtins.trace "profile: ${name}" { inherit imports; }) profile
|
||||||
17
export/nixosUsers.nix
Normal file
17
export/nixosUsers.nix
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
self: { ... }@inputs: { user, ... }@imports: let
|
||||||
|
user' = name: snippets: { pkgs, lib, config, ... }@args:
|
||||||
|
builtins.trace "user: ${name}" {
|
||||||
|
options.fbs42.user.${name} = lib.mkEnableOption name;
|
||||||
|
## no longer with nixos-24.11
|
||||||
|
#config.users.users.${name} = lib.mkIf config.fbs42.user.${name} {
|
||||||
|
# group = lib.mkDefault name;
|
||||||
|
#};
|
||||||
|
|
||||||
|
imports = map ({ user, home-manager}: {
|
||||||
|
config = lib.mkIf config.fbs42.user.${name} {
|
||||||
|
users.users.${name} = (user args);
|
||||||
|
home-manager.users.${name} = home-manager;
|
||||||
|
};
|
||||||
|
}) snippets;
|
||||||
|
};
|
||||||
|
in builtins.mapAttrs user' user
|
||||||
34
export/sdcard-rpi4.nix
Normal file
34
export/sdcard-rpi4.nix
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
{ nixosUsers ? {}, nixosGroups ? {}, nixosModules, hmModules ? { default = {}; }, ...}@flake: { ... }@inputs: { host, ... }@imports: let
|
||||||
|
host' = name: snippets: let
|
||||||
|
|
||||||
|
overlay = self: super: {
|
||||||
|
makeModulesClosure = x: super.makeModulesClosure (x // { allowMissing = true; });
|
||||||
|
};
|
||||||
|
|
||||||
|
common = { modulesPath, lib, ... }: {
|
||||||
|
config.nixpkgs.overlays = [ overlay ];
|
||||||
|
config.networking.hostName = lib.mkForce name;
|
||||||
|
config.home-manager = {
|
||||||
|
sharedModules = [ hmModules.default ] ;
|
||||||
|
};
|
||||||
|
|
||||||
|
imports = [
|
||||||
|
#(modulesPath + "/installer/cd-dvd/installation-cd-minimal-new-kernel-no-zfs.nix")
|
||||||
|
#(modulesPath + "/installer/sd-card/sd-image-aarch64.nix")
|
||||||
|
(modulesPath + "/installer/sd-card/sd-image-raspberrypi.nix")
|
||||||
|
nixosModules.default
|
||||||
|
inputs.home-manager.nixosModules.default
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
system = inputs.nixpkgs.lib.nixosSystem {
|
||||||
|
specialArgs = { inherit inputs flake; };
|
||||||
|
modules = [ common ]
|
||||||
|
++ snippets
|
||||||
|
++ builtins.attrValues nixosUsers
|
||||||
|
++ builtins.attrValues nixosGroups
|
||||||
|
;
|
||||||
|
};
|
||||||
|
in system.config.system.build.sdImage;
|
||||||
|
|
||||||
|
in builtins.mapAttrs host' host
|
||||||
65
flake.lock
generated
Normal file
65
flake.lock
generated
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"hardware": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1735388221,
|
||||||
|
"narHash": "sha256-e5IOgjQf0SZcFCEV/gMGrsI0gCJyqOKShBQU0iiM3Kg=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixos-hardware",
|
||||||
|
"rev": "7c674c6734f61157e321db595dbfcd8523e04e19",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixos-hardware",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"home-manager": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1735344290,
|
||||||
|
"narHash": "sha256-oJDtWPH1oJT34RJK1FSWjwX4qcGOBRkcNQPD0EbSfNM=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "home-manager",
|
||||||
|
"rev": "613691f285dad87694c2ba1c9e6298d04736292d",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"ref": "release-24.11",
|
||||||
|
"repo": "home-manager",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1735922141,
|
||||||
|
"narHash": "sha256-vk0xwGZSlvZ/596yxOtsk4gxsIx2VemzdjiU8zhjgWw=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "d29ab98cd4a70a387b8ceea3e930b3340d41ac5a",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"ref": "nixos-24.11",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"hardware": "hardware",
|
||||||
|
"home-manager": "home-manager",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
12
flake.nix
Normal file
12
flake.nix
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
|
||||||
|
hardware.url = "github:nixos/nixos-hardware";
|
||||||
|
home-manager = {
|
||||||
|
url = "github:nix-community/home-manager/release-24.11";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, ... }@inputs: import ./lib/flake.nix inputs ./.;
|
||||||
|
}
|
||||||
1
group/nix.nix
Normal file
1
group/nix.nix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{}
|
||||||
1
import/group.nix
Normal file
1
import/group.nix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
name: group: group
|
||||||
1
import/group/module.nix
Normal file
1
import/group/module.nix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
name: group'module: group'module
|
||||||
1
import/host.nix
Normal file
1
import/host.nix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
name: host: host
|
||||||
1
import/module.nix
Normal file
1
import/module.nix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
name: module: module
|
||||||
1
import/profile.nix
Normal file
1
import/profile.nix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
name: profile: profile
|
||||||
21
import/user.nix
Normal file
21
import/user.nix
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
let
|
||||||
|
function = name: value: let
|
||||||
|
result = if builtins.isAttrs value then {...}: value else value;
|
||||||
|
result' = builtins.trace "result ${name}=${builtins.typeOf result}" result;
|
||||||
|
in
|
||||||
|
assert builtins.isFunction result';
|
||||||
|
result;
|
||||||
|
|
||||||
|
config = { user?{}, home-manager?{} }@set:
|
||||||
|
builtins.mapAttrs function { inherit user home-manager; };
|
||||||
|
|
||||||
|
in name: value: let
|
||||||
|
result = if builtins.isFunction value
|
||||||
|
then
|
||||||
|
config { user = value; }
|
||||||
|
else if builtins.any (attr: builtins.hasAttr attr value) [ "user" "home-manager" ]
|
||||||
|
then
|
||||||
|
config value
|
||||||
|
else
|
||||||
|
config { user = value; };
|
||||||
|
in result
|
||||||
1
import/user/module.nix
Normal file
1
import/user/module.nix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
iname: user'module: user'module
|
||||||
2
import/user/profile.nix
Normal file
2
import/user/profile.nix
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
name: profile: profile
|
||||||
|
|
||||||
34
lib/flake.nix
Normal file
34
lib/flake.nix
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
let
|
||||||
|
scan = import ./scan.nix;
|
||||||
|
|
||||||
|
flake' = self: { imports, exports , base }@schema: { ... }@inputs: { ... }@imports: let
|
||||||
|
lib = {
|
||||||
|
inherit scan schema inputs imports;
|
||||||
|
extend = flake schema inputs imports;
|
||||||
|
new = flake {} {} {};
|
||||||
|
# TODO: override
|
||||||
|
};
|
||||||
|
convert = attr: value: value self inputs imports;
|
||||||
|
|
||||||
|
result = (builtins.mapAttrs convert schema.exports);
|
||||||
|
in result // { lib = lib // (result.lib or {}); };
|
||||||
|
|
||||||
|
flake = { imports?{}, exports?{}, base?[] }@schema'old: { ... }@inputs'old: { ... }@imports'old: { ... }@inputs'new: base: let
|
||||||
|
schema = {
|
||||||
|
imports = (schema'old.imports or {}) // scan { base = base + "/import"; recursive = true; };
|
||||||
|
exports = (schema'old.exports or {}) // scan { base = base + "/export"; };
|
||||||
|
base = [ base ] ++ (schema'old.base or []);
|
||||||
|
};
|
||||||
|
|
||||||
|
merge = attr: let
|
||||||
|
old = imports'old.${attr} or {};
|
||||||
|
new = imports'new.${attr} or {};
|
||||||
|
in builtins.mapAttrs (attr: _: (old.${attr} or []) ++ (new.${attr} or [])) (old//new);
|
||||||
|
|
||||||
|
imports'new = builtins.mapAttrs (name: value: scan { base = base + "/${name}"; convert = name: content: [ (value name content) ]; }) schema.imports;
|
||||||
|
result = flake' result schema
|
||||||
|
(inputs'old // (builtins.removeAttrs inputs'new ["self"]))
|
||||||
|
(builtins.mapAttrs (attr: _: merge attr) schema.imports);
|
||||||
|
in result;
|
||||||
|
|
||||||
|
in flake {} {} {}
|
||||||
1
lib/host.nix
Normal file
1
lib/host.nix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
self:
|
||||||
23
lib/scan.nix
Normal file
23
lib/scan.nix
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
{ base, convert ? name: value: value, recursive ? false }:
|
||||||
|
let
|
||||||
|
scan = sub: let
|
||||||
|
all = builtins.readDir (base + "/${builtins.concatStringsSep "/" sub}");
|
||||||
|
names = filter: builtins.filter filter (builtins.attrNames all);
|
||||||
|
nix = name: all.${name} == "regular" && builtins.stringLength name > 4 && builtins.substring (builtins.stringLength name - 4) 4 name == ".nix";
|
||||||
|
dir = name: all.${name} == "directory";
|
||||||
|
files = map (name: sub ++ [ (builtins.substring 0 (builtins.stringLength name - 4) name) ]) (names nix);
|
||||||
|
dirs = builtins.concatLists (map (name: scan (sub ++ [name])) (names dir));
|
||||||
|
in if recursive then files ++ dirs else files;
|
||||||
|
|
||||||
|
root = scan [];
|
||||||
|
|
||||||
|
item = relative: let
|
||||||
|
name = builtins.concatStringsSep "/" relative;
|
||||||
|
absolute = base + "/${name}.nix";
|
||||||
|
content = import absolute;
|
||||||
|
value = convert name content;
|
||||||
|
in { inherit name value; };
|
||||||
|
|
||||||
|
items = map item root;
|
||||||
|
|
||||||
|
in if builtins.pathExists base then builtins.listToAttrs (map item root) else {}
|
||||||
1
user/root.nix
Normal file
1
user/root.nix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue