diff --git a/hosts/mandos/README.md b/_hosts/mandos/README.md similarity index 100% rename from hosts/mandos/README.md rename to _hosts/mandos/README.md diff --git a/hosts/mandos/default.nix b/_hosts/mandos/default.nix similarity index 100% rename from hosts/mandos/default.nix rename to _hosts/mandos/default.nix diff --git a/hosts/mandos/hardware.nix b/_hosts/mandos/hardware.nix similarity index 100% rename from hosts/mandos/hardware.nix rename to _hosts/mandos/hardware.nix diff --git a/hosts/mandos/users/chris/default.nix b/_hosts/mandos/users/chris/default.nix similarity index 100% rename from hosts/mandos/users/chris/default.nix rename to _hosts/mandos/users/chris/default.nix diff --git a/_lib/attrs.nix b/_lib/attrs.nix deleted file mode 100644 index 9a576b2..0000000 --- a/_lib/attrs.nix +++ /dev/null @@ -1,21 +0,0 @@ -{ lib, ... }: -let - inherit (lib.lists) any count; - inherit (lib.attrsets) filterAttrs listToAttrs mapAttrs' mapAttrsToList; -in rec -{ - attrsToList = attrs: - mapAttrsToList (name: value: { inherit name value; }) attrs; - - mapFilterAttrs = pred: f: attrs: - filterAttrs pred (mapAttrs' f attrs); - - getAttrs' = values: f: - listToAttrs (map f values); - - anyAttrs = pred: attrs: - any (attr: pred attr.name attr.value) (attrsToList attrs); - - countAttrs = pred: attrs: - count (attr: pred attr.name attr.value) (attrsToList attrs); -} diff --git a/_lib/default.nix b/_lib/default.nix deleted file mode 100644 index 38cfde6..0000000 --- a/_lib/default.nix +++ /dev/null @@ -1,22 +0,0 @@ -{ inputs, lib, pkgs, ... }: -let - inherit (lib.attrsets) attrValues; - inherit (lib.fixedPoints) makeExtensible; - inherit (lib.lists) foldr; - inherit (modules) mapModules; - - modules = import ./modules.nix { - inherit lib; - - self.attrs = import ./attrs.nix { - inherit lib; - - self = {}; - }; - }; - - mylib = makeExtensible (self: - mapModules ./. (file: import file { inherit self lib pkgs inputs; }) - ); -in - mylib.extend (self: super: foldr (a: b: a // b) {} (attrValues super)) diff --git a/_lib/modules.nix b/_lib/modules.nix deleted file mode 100644 index ecc5dc9..0000000 --- a/_lib/modules.nix +++ /dev/null @@ -1,52 +0,0 @@ -{ lib, self, ... }: -let - inherit (builtins) attrValues readDir pathExists concatLists replaceStrings listToAttrs; - inherit (lib.attrsets) mapAttrsToList filterAttrs nameValuePair; - inherit (lib.strings) hasPrefix hasSuffix removeSuffix removePrefix; - inherit (lib.trivial) id; - inherit (lib) flatten; - inherit (self.attrs) mapFilterAttrs; -in rec -{ - mapModules = dir: fn: - mapFilterAttrs (n: v: v != null && !(hasPrefix "_" n)) (n: v: let path = "${toString dir}/${n}"; in - if v == "directory" && pathExists "${path}/default.nix" - then nameValuePair n (fn path) - else if v == "regular" && n != "default.nix" && hasSuffix ".nix" n && !(hasPrefix "_" n) - then nameValuePair (removeSuffix ".nix" n) (fn path) - else nameValuePair "" null - ) (readDir dir); - - mapModules' = dir: fn: attrValues (mapModules dir fn); - - mapModulesRec = dir: fn: - mapFilterAttrs (n: v: v != null && !(hasPrefix "_" n)) (n: v: let path = "${toString dir}/${n}"; in - if v == "directory" && pathExists "${path}/default.nix" - then nameValuePair n (mapModulesRec path fn) - else if v == "regular" && n != "default.nix" && hasSuffix ".nix" n - then nameValuePair (removeSuffix ".nix" n) (fn path) - else nameValuePair "" null - ) (readDir dir); - - mapModulesRec' = dir: fn: let - dirs = mapAttrsToList (k: _: "${dir}/${k}") (filterAttrs (n: v: v == "directory" && !(hasPrefix "_" n)) (readDir dir)); - files = attrValues (mapModules dir id); - paths = files ++ concatLists (map (d: mapModulesRec' d id) dirs); - in - map fn paths; - - readNixosModules = dir: fn: filterAttrs (name: value: value != null && !(hasPrefix "_" name)) (listToAttrs (flatten (readDirRecursive fn dir ""))); - - readDirRecursive = fn: root: dir: mapAttrsToList (name: type: - if type == "directory" && pathExists "${root}/${dir}/${name}/default.nix" - then [ - (nameValuePair "${replaceStrings ["/"] ["_"] (removePrefix "/" dir)}_${name}" (fn "${root}/${dir}/${name}/default.nix")) - (readDirRecursive fn root "${dir}/${name}") - ] - else if type == "directory" - then readDirRecursive fn root "${dir}/${name}" - else if type == "regular" && name != "default.nix" && hasSuffix ".nix" name - then nameValuePair "${replaceStrings ["/"] ["_"] (removePrefix "/" dir)}_${removeSuffix ".nix" name}" (fn "${root}/${dir}/${name}") - else nameValuePair "" null - ) (readDir "${root}/${dir}"); -} diff --git a/_lib/nixos.nix b/_lib/nixos.nix deleted file mode 100644 index b99ffaf..0000000 --- a/_lib/nixos.nix +++ /dev/null @@ -1,73 +0,0 @@ -{ inputs, lib, pkgs, self, ... }: let - inherit (inputs.nixpkgs.lib) nixosSystem; - inherit (builtins) baseNameOf elem map listToAttrs pathExists; - inherit (lib) filterAttrs nameValuePair attrNames; - inherit (lib.modules) mkDefault mkIf; - inherit (lib.strings) removeSuffix; - inherit (self.modules) mapModules mapModulesRec'; - inherit (self) mkSysUser; -in rec -{ - mkHost = path: attrs @ {system ? "x86_64-linux", ...}: - nixosSystem { - inherit system; - - specialArgs = {inherit lib inputs system; }; - - modules = let - stateVersion = "23.11"; - users = if (pathExists "${path}/users") then attrNames (mapModules "${path}/users" (p: p)) else []; - in [ - inputs.nixos-boot.nixosModules.default - ({ ... }: { - nixpkgs.pkgs = pkgs; - - networking.hostName = mkDefault (removeSuffix ".nix" (baseNameOf path)); - - system = { - inherit stateVersion; - configurationRevision = mkIf (self ? rev) self.rev; - }; - - imports = [ - inputs.home-manager.nixosModules.home-manager - "${path}/hardware.nix" - ] - ++ (mapModulesRec' ../modules/system import); - - users = { - mutableUsers = true; # Set this to false when I get sops with passwords set up properly - users = mkIf (pathExists "${path}/users") (mapModules "${path}/users" mkSysUser); - }; - }) - (filterAttrs (n: v: !elem n ["system"]) attrs) - (import path) - (args@{ inputs, lib, pkgs, config, options, ... }: { - imports = mapModulesRec' ../modules/home (file: (import file (args // { user = "root"; }))); - }) - ({...}: { - imports = []; - - config = { - home-manager = { - backupFileExtension = "bak"; - useGlobalPkgs = true; - sharedModules = [ - inputs.plasma-manager.homeManagerModules.plasma-manager - ]; - - users = listToAttrs (map (user: (nameValuePair user { home = { inherit stateVersion; }; })) (users ++ ["root"])); - }; - }; - }) - ] - ++ (map (user: (args@{ inputs, lib, pkgs, config, options, ... }: { - imports = mapModulesRec' ../modules/home (file: (import file (args // { inherit user; }))); - - config.modules.${user} = (import "${path}/users/${user}/default.nix" args); - })) users); - }; - - mapHosts = dir: attrs @ {system ? system, ...}: - mapModules dir (hostPath: mkHost hostPath attrs); -} diff --git a/_lib/options.nix b/_lib/options.nix deleted file mode 100644 index ca175d6..0000000 --- a/_lib/options.nix +++ /dev/null @@ -1,8 +0,0 @@ -{lib, ...}: let - inherit (lib.options) mkOption; -in { - mkOpt = type: default: mkOption {inherit type default;}; - - mkOpt' = type: default: description: - mkOption {inherit type default description;}; -} diff --git a/_lib/user.nix b/_lib/user.nix deleted file mode 100644 index 3e1eb2b..0000000 --- a/_lib/user.nix +++ /dev/null @@ -1,26 +0,0 @@ -{ lib, ... }: let - inherit (builtins) baseNameOf; - inherit (lib.attrsets) filterAttrs; - inherit (lib.strings) removeSuffix; - inherit (lib.my) mapModulesRec'; -in rec -{ - mkSysUser = path: let - name = removeSuffix ".nix" (baseNameOf path); - in - { - inherit name; - isNormalUser = true; - initialPassword = "kaas"; - home = "/home/${name}"; - group = "users"; - }; - - mkHmUser = path: {stateVersion, ...}: - { - home = { - inherit stateVersion; - sessionPath = [ "$XDG_BIN_HOME" "$PATH" ]; # Pretty sure I don't need this. - }; - }; -}