diff --git a/nix/configModule/default.nix b/nix/configModule/default.nix index 5621907..f9bc117 100644 --- a/nix/configModule/default.nix +++ b/nix/configModule/default.nix @@ -1,12 +1,28 @@ -{ - mkModuleArgs = import ./mkModuleArgs.nix; - modules = [ - ./alacritty.nix - ./git.nix - ./ssh.nix - ./shells.nix - { - config.programs.home-manager.enable = true; - } - ]; +let + # these are configured to work with home-manager with some mutations that are + # reconfigurable + homeModules = [ + ./alacritty.nix + ./git.nix + ./ssh.nix + ./shells.nix + ./neovim.nix + ./home.req.nix + { + config.programs.home-manager.enable = true; + } + ]; + # These are the modules that should be used only in nixosConfigurations + # since it relies on root permission to run + serviceModules = [ + ./gitea.service.nix + ./vault.service.nix + ./tailscale.service.nix + ]; + allModules = homeModules ++ serviceModules; +in +{ + mkModuleArgs = import ./mkModuleArgs.nix; + modules = allModules; + inherit homeModules serviceModules; } diff --git a/nix/configModule/git.nix b/nix/configModule/git.nix index 8db840b..aa8af9a 100644 --- a/nix/configModule/git.nix +++ b/nix/configModule/git.nix @@ -66,9 +66,10 @@ in example = 3000; }; }; -# TODO : anyway to override configuration? - config.programs.git = { - inherit (cfg) enable ignores; + # TODO : anyway to override configuration? + config.programs.git = lib.mkIf cfg.enable { + inherit (cfg) ignores; + enable = true; userName = cfg.name; userEmail = cfg.email; aliases = baseAliases // cfg.aliases; diff --git a/nix/configModule/home.req.nix b/nix/configModule/home.req.nix new file mode 100644 index 0000000..8138475 --- /dev/null +++ b/nix/configModule/home.req.nix @@ -0,0 +1,18 @@ +{ config, pkgs, lib, ... }@input: +let + cfg = config.base.home; + types = lib.types; +in +{ + options.base.home = { + packages = lib.mkOption { + type = types.listOf types.package; + description = "Addtional packages that are available at user level"; + default = [ ]; + example = [ pkgs.python310Full pkgs.ripgrep ]; + }; + user = lib.mkOption { + + }; + }; +} diff --git a/nix/configModule/mkModuleArgs.nix b/nix/configModule/mkModuleArgs.nix deleted file mode 100644 index 358470f..0000000 --- a/nix/configModule/mkModuleArgs.nix +++ /dev/null @@ -1,16 +0,0 @@ -# This shows the config fields that these modules are expected to have -# usage: [extra]specialArgs = mkModuleArgs {pkgs, lib,...} @ inputs -# Note that mkModuleArgs also recursively merges `inputs` -{ pkgs -, lib ? pkgs.lib -, ... -}@inputs: -let - recursiveUpdate = lib.recursiveUpdate; - _lib = recursiveUpdate lib (import ../../lib { inherit pkgs lib; }); -in -# TODO: Unpollute inputs -recursiveUpdate inputs { - proj_root = builtins.toString ./../../..; - myLib = _lib; -} diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..9c37cf9 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1 @@ +import diff --git a/nix/flake.lock b/nix/flake.lock new file mode 100644 index 0000000..54d7631 --- /dev/null +++ b/nix/flake.lock @@ -0,0 +1,216 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1668681692, + "narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "009399224d5e398d03b22badca40a37ac85412a1", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1644229661, + "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils-plus": { + "inputs": { + "flake-utils": "flake-utils" + }, + "locked": { + "lastModified": 1657226504, + "narHash": "sha256-GIYNjuq4mJlFgqKsZ+YrgzWm0IpA4axA3MCrdKYj7gs=", + "owner": "gytis-ivaskevicius", + "repo": "flake-utils-plus", + "rev": "2bf0f91643c2e5ae38c1b26893ac2927ac9bd82a", + "type": "github" + }, + "original": { + "owner": "gytis-ivaskevicius", + "repo": "flake-utils-plus", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "utils": "utils" + }, + "locked": { + "lastModified": 1670970889, + "narHash": "sha256-TWJo3/X3Q3r+HeX16QN4FE6ddBpGtAboymSEF+4Nnc0=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "e412025fffdcd6219ddd21c65d9a1b90005ce508", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "nixgl": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1661367362, + "narHash": "sha256-Qc8MXcV+YCPREu8kk6oggk23ZBKLqeQRAIsLbHEviPE=", + "owner": "guibou", + "repo": "nixGL", + "rev": "7165ffbccbd2cf4379b6cd6d2edd1620a427e5ae", + "type": "github" + }, + "original": { + "owner": "guibou", + "repo": "nixGL", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1660551188, + "narHash": "sha256-a1LARMMYQ8DPx1BgoI/UN4bXe12hhZkCNqdxNi6uS0g=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "441dc5d512153039f19ef198e662e4f3dbb9fd65", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1671021324, + "narHash": "sha256-MDB6TncBzBCvAgQmjNn14VIaO5wdbxExp8NGP990Udk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "62433a4892603c523840a67e50b6631c37adb928", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1665296151, + "narHash": "sha256-uOB0oxqxN9K7XGF1hcnY+PQnlQJ+3bP2vCn/+Ru/bbc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "14ccaaedd95a488dd7ae142757884d8e125b3363", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils-plus": "flake-utils-plus", + "home-manager": "home-manager", + "nixgl": "nixgl", + "nixpkgs": "nixpkgs_2", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils_3", + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1671071423, + "narHash": "sha256-zUldhyWANdgko+lqQuB1Eee7TyYya1KiOS0SCd/Y268=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "684659b7ca903e512a421bc6ade689fb26e509b4", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/nix/flake.nix b/nix/flake.nix index e2bf7b7..8a9f139 100644 --- a/nix/flake.nix +++ b/nix/flake.nix @@ -14,23 +14,44 @@ url = "github:edolstra/flake-compat"; flake = false; }; - naersk.url = "gihub:nix-community/naersk"; + # naersk.url = "gihub:nix-community/naersk"; }; - outputs = { nixpkgs, ... } @ inputs: - let - # init config - overlays = [ nixgl.overlay rust-overlay.overlays.default ]; - pkgs = import nixpkgs { inherit overlays; }; - _lib = pkgs.lib; - lib = _lib.recursiveUpdate _lib import ./lib { inherit pkgs; }; - - # module collecting - hosts = import ./hosts { inherit pkgs lib; }; - users = import ./users { inherit pkgs lib; }; - in + outputs = { nixpkgs, nixgl, rust-overlay, flake-utils-plus, ... } @ inputs: { - inherit pkgs lib overlays; - nixosConfigurations = hosts; - homeConfigurations = users; + # HACK: + # this is to get multiple platforms support for home-manager + # see https://github.com/nix-community/home-manager/issues/3075#issuecomment-1330661815 + # Expect this to change quite in some near future + # packages.linux_something.{nixosConfigurations,homeConfigurations} + packages = builtins.foldl' + (so_far: system: ( + let + # init config + overlays = [ nixgl.overlay rust-overlay.overlays.default ]; + pkgs = import nixpkgs { inherit system overlays; }; + _lib = pkgs.lib; + lib = _lib.recursiveUpdate _lib import ./lib { inherit pkgs; }; + configModule = import ./configModule; + moduleInputs = lib.recursiveUpdate inputs { inherit pkgs lib configModule; }; + + # module collecting + hosts = import ./hosts moduleInputs; + users = import ./users moduleInputs; + exportSystems = { nixosConfigurations, homeConfigurations }@_configs: { + packages.${system} = { + inherit (_configs) nixosConfigurations homeConfigurations; + }; + }; + in + so_far // { + ${system} = { + inherit pkgs lib overlays; + nixosConfigurations = hosts; + homeConfigurations = users; + }; + } + )) + { } + flake-utils-plus.lib.defaultSystems; }; } diff --git a/nix/hardwareConfig/linode.template.nix b/nix/hardwareConfig/linode.template.nix new file mode 100644 index 0000000..e69de29 diff --git a/nix/hosts/hwtr/nix.conf b/nix/hosts/hwtr/nix.conf index e69de29..44fd85b 100644 --- a/nix/hosts/hwtr/nix.conf +++ b/nix/hosts/hwtr/nix.conf @@ -0,0 +1,2 @@ +accept-flake-config = true +experimental-features = nix-command flakes diff --git a/nix/hosts/linode.template.nix b/nix/hosts/linode.template.nix new file mode 100644 index 0000000..e69de29 diff --git a/nix/lib/moduleUtils.nix b/nix/lib/moduleUtils.nix index 879d977..6647f5a 100644 --- a/nix/lib/moduleUtils.nix +++ b/nix/lib/moduleUtils.nix @@ -7,4 +7,18 @@ exportWithInputs = modules: inputs: ( lib.mapAttrs (name: value: (value inputs)) (flake-utils-plus.lib.exportModules modules)); + mkModuleArgs = + # This shows the config fields that these modules are expected to have + # usage: [extra]specialArgs = mkModuleArgs {pkgs, lib,...} @ inputs + # Note that mkModuleArgs also recursively merges `inputs` + { pkgs, lib ? pkgs.lib, ... }@inputs: + let + recursiveUpdate = lib.recursiveUpdate; + _lib = recursiveUpdate lib (import ../../lib { inherit pkgs lib; }); + in + # TODO: Unpollute inputs + recursiveUpdate inputs { + proj_root = builtins.toString ./../..; + myLib = _lib; + }; } diff --git a/nix/users/hungtr.nix b/nix/users/hungtr.nix index ee08ddd..cb4686c 100644 --- a/nix/users/hungtr.nix +++ b/nix/users/hungtr.nix @@ -1,8 +1,31 @@ -{ ... }@inputs: { - users.users.hungtr = { - isNormalUser = true; - home = "/home/hungtr"; - description = "pegasust/hungtr"; - extraGroups = [ "wheel" "networkmanager" ]; +{ home-manager, lib, pkgs, configModule, ... }@inputs: { + # end result: homeConfigurations.hwtr = home-manager... + homeConfig = home-manager.lib.homeManagerConfiguration { + inherit pkgs; + modules = configModule.homeModules ++ [ + { + base.alacritty.font.family = "BitstreamVeraSansMono Nerd Font"; + base.shells = { + shellAliases = { + nixGL = "nixGLIntel"; + }; + }; + users.users.hungtr = { + isNormalUser = true; + home = "/home/hungtr"; + description = "pegasust/hungtr"; + extraGroups = [ "wheel" "networkmanager" ]; + }; + } + ]; + extraSpecialArgs = lib.mkModuleArgs { + inherit pkgs; + myHome = { + packages = [ + pkgs.nixgl.nixGLIntel + pkgs.postman + ]; + }; + }; }; } diff --git a/nix/users/hwtr.nix b/nix/users/hwtr.nix index 73a83a9..625dd7d 100644 --- a/nix/users/hwtr.nix +++ b/nix/users/hwtr.nix @@ -3,7 +3,7 @@ homeConfig = home-manager.lib.homeManagerConfiguration { inherit pkgs; modules = base.modules ++ [ - ./home.nix + ./home.req.nix { base.alacritty.font.family = "BitstreamVeraSansMono Nerd Font"; base.shells = { @@ -13,7 +13,7 @@ }; } ]; - extraSpecialArgs = mkModuleArgs { + extraSpecialArgs = lib.mkModuleArgs { inherit pkgs; myHome = { username = "hwtr";