diff options
| author | Mike Vink <mike@pionative.com> | 2024-07-14 06:40:52 +0200 |
|---|---|---|
| committer | Mike Vink <mike@pionative.com> | 2024-07-14 06:40:52 +0200 |
| commit | 98c31cac3e931023b5afeb209af6b6eed2a025c7 (patch) | |
| tree | 4f78891affa3ce2cfbb7f0b1b3efc31d68c87ab7 /lib | |
| parent | f56f38fc344a80244266e0b69f909775599ba5b2 (diff) | |
wip
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/default.nix | 69 | ||||
| -rw-r--r-- | lib/machine.nix | 98 | ||||
| -rw-r--r-- | lib/my.nix | 110 |
3 files changed, 277 insertions, 0 deletions
diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 0000000..960a7a4 --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,69 @@ +inputs: lib: prev: with lib; rec { + modulesAttrsIn = dir: pipe dir [ + builtins.readDir + (mapAttrsToList (name: type: + if type == "regular" && hasSuffix ".nix" name && name != "default.nix" then + [ { name = removeSuffix ".nix" name; value = dir + "/${name}"; } ] + else if type == "directory" && pathExists (dir + "/${name}/default.nix") then + [ { inherit name; value = dir + "/${name}"; } ] + else + [] + )) + concatLists + listToAttrs + ]; + + modulesIn = dir: attrValues (modulesAttrsIn dir); + + # Collects the inputs of a flake recursively (with possible duplicates). + collectFlakeInputs = input: + [ input ] ++ concatMap collectFlakeInputs (builtins.attrValues (input.inputs or {})); + + my = import ./my.nix inputs.self lib; + + mkMachines = import ./machine.nix lib; + + # Gets module from ./machines/ and uses the lib to define which other modules + # the machine needs. + mkSystem = machines: name: systemInputs @ { + system, + modules, + opts, + ... + }: + let + machine = machines.${name}; + in + lib.nixosSystem { + inherit lib system; + specialArgs = { + inherit (inputs) self; + inherit machines machine inputs; + }; + modules = + modules + ++ + (if lib.hasInfix "darwin" system then + [inputs.home-manager.darwinModules.default] + else + [inputs.home-manager.nixosModules.default]) + ++ [ + ({pkgs, ...}: { + nixpkgs.overlays = with lib; [ + (composeManyExtensions [ + (import ../overlays/vimPlugins.nix {inherit pkgs;}) + (import ../overlays/openpomodoro-cli.nix {inherit pkgs lib;}) + inputs.neovim-nightly-overlay.overlays.default + ]) + ]; + }) + ]; + }; + + mkSystems = systems: + let + machines = mkMachines (mapAttrs (name: value: value.opts) systems); + in + (mapAttrs (mkSystem machines) systems); + +} diff --git a/lib/machine.nix b/lib/machine.nix new file mode 100644 index 0000000..10e766f --- /dev/null +++ b/lib/machine.nix @@ -0,0 +1,98 @@ +lib: systemOptions: with lib; let + modules = [ + { + options.machines = mkOption { + description = "Machine options"; + default = {}; + type = with types; attrsOf (submodule ({ name, config, ... }: { + freeformType = attrs; + options = { + modules = mkOption { + description = "Final list of modules to import"; + type = listOf str; + default = []; + }; + profiles = mkOption { + description = "List of profiles to use"; + type = listOf str; + default = []; + }; + hostname = mkOption { + description = "The machine's hostname"; + type = str; + readOnly = true; + default = name; + }; + ipv4 = mkOption { + description = "The machines public IPv4 addresses"; + type = listOf str; + default = []; + }; + ipv6 = mkOption { + description = "The machines public IPv6 addresses"; + type = listOf str; + default = []; + }; + isStation = mkOption { + description = "The machine is a desktop station"; + type = bool; + default = false; + }; + isServer = mkOption { + description = "The machine is a server"; + type = bool; + default = false; + }; + isFake = mkOption { + description = "The machine is a fake machine"; + type = bool; + default = false; + }; + isDarwin = mkOption { + description = "The machine is a fake machine"; + type = bool; + default = false; + }; + tailnet = mkOption { + default = {}; + type = with types; attrsOf (submodule ({ name, config, ... }: { + options = { + ipv4 = mkOption { + description = "The machine's tailnet IPv4 address"; + type = str; + default = null; + }; + ipv6 = mkOption { + description = "The machine's tailnet IPv6 address"; + type = str; + default = null; + }; + nodeKey = mkOption { + description = "The machine's tailnet public key"; + type = str; + default = null; + }; + }; + })); + }; + syncthing = mkOption { + default = {}; + type = with types; submodule { + freeformType = attrs; + options = { + id = mkOption { + description = "The machine's syncting public id"; + type = str; + default = ""; + }; + enable = mkEnableOption "Add to syncthing cluster"; + }; + }; + }; + }; + })); + }; + config.machines = systemOptions; + } + ]; +in (evalModules { inherit modules; }).config.machines diff --git a/lib/my.nix b/lib/my.nix new file mode 100644 index 0000000..5033ae9 --- /dev/null +++ b/lib/my.nix @@ -0,0 +1,110 @@ +self: lib: with lib; let + modules = [ + { + config = { + _module.freeformType = with types; attrs; + + username = "ivi"; + githubUsername = "ivi-vink"; + realName = "Mike Vink"; + domain = "vinkies.net"; + email = "ivi@vinkies.net"; + sshKeys = [ + "sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29tAAAAIPZHOBNQdo5oBnQ8f147QtelhLmYItiruoNfoHF89qrJAAAABHNzaDo= ivi@lemptop" + "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDqsfYS7sOLfLWvGTmxT2QYGkbXJ5kREFl42n3jtte5sLps76KECgKqEjA4OLhNZ51lKFBDzcn1QOUl3RN4+qHsBtkr+02a7hhf1bBLeb1sx6+FVXdsarln5lUF/NMcpj6stUi8mqY4aQ21jQKxZsGip9fI8fx3HtXYCVhIarRbshQlwDqTplJBLDtrnmWTprxVnz1xSZRr3euXsIh1FFQZI6klPPBa6qFJtWWtGNBCRr8Sruo6I4on7QjNyW/s1OgiNAR0N2IO9wCdjlXrjNnFEAaMrpDpZde7eULbiFP2pHYVVy/InwNhhePYkeBh/4BzlaUZVv6gXsX7wOC5OyWaXbbMzWEopbnqeXXLwNyOZ88YpN/c+kZk2/1CHl+xmlVGAr9TnZ9VST5Y4ZAEqq8OKoP3ZcchAWxWjzTgPogSfiIAP/n5xrgB+8uRZb/gkN+I7RTQKGrS2Ex7gfkj39beDeevQj3XVQ1U2kp3n+jUBHItCCpZyHISgTYW2Ct6lrziJpD0kPlAOrN3BGQtkStHYK+4EE1PrrwWGkG7Ue+tlETe8FTg+AMv1VjLV9b3pHZJCrao5/cY2MxkfGzf4HTfeueqSLSsrYuiogHAPvvzfvOV5un+dWX8HyeBjmKTBwDBFuhdca/wzk0ArHSgEYUmh2NXj/G4gaSF3EX5ZSxmMQ== ${my.email}" + ]; + + # machines = { + # wsl = { + # isFake = true; + # profiles = [ + # "core" + # ]; + # }; + # vm-aarch64 = { + # isStation = true; + # profiles = [ + # "core" + # "graphical" + # ]; + # syncthing = { + # enable = true; + # id = "LDZVZ6H-KO3BKC6-FMLZOND-MKXI4DF-SNT27OT-Q5KMN2M-A2DYFNQ-3BWUYA6"; + # }; + # }; + # persephone = { + # isFake = true; + # tailnet = { + # ipv4 = "100.72.127.82"; + # ipv6 = "fd7a:115c:a1e0::9c08:7f52"; + # nodeKey = "nodekey:2ffbb54277ba6c29337807b74f69438eba4d3802bffbe9c7df4093139c087f51"; + # }; + # }; + # bellerophone = { + # isFake = true; + # tailnet = { + # ipv4 = "100.123.235.65"; + # ipv6 = "fd7a:115c:a1e0::bafb:eb41"; + # nodeKey = "nodekey:e2a9f948a1252a4b1f1932bb99e73981fa0b7173825b54ba968f9cc0bafbeb40"; + # }; + # syncthing = { + # enable = true; + # id = "75U7B2F-SZOJRY2-UKAADJD-NI3R5SJ-K4J35IN-D2NJJFJ-JG5TCJA-AUERDAA"; + # }; + # }; + # serber = { + # isServer = true; + # profiles = [ + # "core" + # "server" + # ]; + # ipv4 = [ "65.109.143.65" ]; + # ipv6 = [ "2a01:4f9:c012:ccc2::1" ]; + # }; + # work = { + # isDarwin = true; + # profiles = [ + # "core" + # ]; + # syncthing = { + # enable = true; + # id = "GR5MHK2-HDCFX4I-Y7JYKDN-EFTQFG6-24CXSHB-M5C6R3G-2GWX5ED-VEPAQA7"; + # }; + # }; + # lemptop = { + # isStation = true; + # profiles = [ + # "core" + # "graphical" + # "station" + # "email" + # "netboot" + # ]; + # syncthing = { + # enable = true; + # id = "TGRWV6Z-5CJ4KRI-4VDTIUE-UA5LQYS-3ARZGNK-KL7HGXP-352PB5Q-ADTV6Q2"; + # }; + # }; + # pump = { + # isServer = true; + # profiles = [ + # "core" + # "homeserver" + # ]; + # ipv4 = [ "192.168.2.13" ]; + # ipv6 = [ "2a02:a46b:ee73:1:c240:4bcb:9fc3:71ab" ]; + # tailnet = { + # ipv4 = "100.90.145.95"; + # ipv6 = "fd7a:115c:a1e0::e2da:915f"; + # nodeKey = "nodekey:dcd737aab30c21eb4f44a40193f3b16a8535ffe2fb5008904b39bb54e2da915e"; + # }; + # syncthing = { + # enable = true; + # id = "7USTCMT-QZTLGPL-5FCRKJW-BZUGMOS-H7D2TTK-F4COYPG-5D7VUO2-QFME2AS"; + # }; + # }; + # }; + }; + } + ]; +in (evalModules { inherit modules; }).config |
