From f4373bac52d1f5d929f0dd845a289801f5195f12 Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Wed, 28 Aug 2024 18:17:55 +0200 Subject: [PATCH] lib: initial commit, start of custom lib --- flake.nix | 10 ++--- hosts/default.nix | 84 ++++++++++++++++++------------------ parts/default.nix | 3 +- parts/fmt.nix | 5 ++- parts/lib/builders.nix | 31 +++++++++++++ parts/lib/default.nix | 17 ++++++++ parts/lib/systemd.nix | 0 parts/pre-commit/default.nix | 13 ------ parts/shell.nix | 10 +---- 9 files changed, 102 insertions(+), 71 deletions(-) create mode 100644 parts/lib/builders.nix create mode 100644 parts/lib/default.nix create mode 100644 parts/lib/systemd.nix delete mode 100644 parts/pre-commit/default.nix diff --git a/flake.nix b/flake.nix index dfd3e1f..d2ab0cb 100644 --- a/flake.nix +++ b/flake.nix @@ -1,16 +1,13 @@ { description = "My NixOS config flake"; outputs = inputs: - inputs.flake-parts.lib.mkFlake {inherit inputs;} ({withSystem, ...}: { + inputs.flake-parts.lib.mkFlake {inherit inputs;} { systems = ["x86_64-linux"]; imports = [ ./parts + ./hosts ]; - - flake = { - nixosConfigurations = import ./hosts {inherit inputs withSystem;}; - }; - }); + }; inputs = { # what am I doing to this config help flake-parts.url = "github:hercules-ci/flake-parts"; @@ -58,6 +55,7 @@ emacs-overlay.url = "github:nix-community/emacs-overlay"; + # I use schizofox as my personal browser. This is because I am schizophrenic. schizofox = { url = "github:schizofox/schizofox"; inputs = { diff --git a/hosts/default.nix b/hosts/default.nix index 8f2d520..dcd8ecb 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -3,49 +3,51 @@ withSystem, ... }: let - inherit (inputs) self; + # inherit (inputs) self; inherit (inputs.nixpkgs) lib; - - mkSystem = { - withSystem, - system, - ... - } @ args: - withSystem system ( - { - inputs', - self', - ... - }: - lib.nixosSystem { - inherit system; - specialArgs = - lib.recursiveUpdate - { - inherit lib; - inherit inputs inputs'; - inherit self self'; - } - (args.specialArgs or {}); - inherit (args) modules; - } - ); + inherit (lib.builders) mkSystem; + # mkSystem = { + # withSystem, + # system, + # ... + # } @ args: + # withSystem system ( + # { + # inputs', + # self', + # ... + # }: + # lib.nixosSystem { + # inherit system; + # specialArgs = + # lib.recursiveUpdate + # { + # inherit lib; + # inherit inputs inputs'; + # inherit self self'; + # } + # (args.specialArgs or {}); + # inherit (args) modules; + # } + # ); in { - temperance = mkSystem { - inherit withSystem; - system = "x86_64-linux"; - modules = [ - ./vali/temperance - ../modules - ]; - }; + flake.nixosConfigurations = { + temperance = mkSystem { + inherit withSystem; + system = "x86_64-linux"; + modules = [ + ./vali/temperance + ../modules + ]; + }; - hermit = mkSystem { - inherit withSystem; - system = "x86_64-linux"; - modules = [ - ./vali/hermit - ../modules - ]; + hermit = mkSystem { + inherit withSystem; + system = "x86_64-linux"; + modules = [ + ./vali/hermit + ../modules + ]; + }; }; } diff --git a/parts/default.nix b/parts/default.nix index 7d1398d..9e3cfa2 100644 --- a/parts/default.nix +++ b/parts/default.nix @@ -1,7 +1,8 @@ _: { imports = [ - # ./fmt.nix + ./fmt.nix ./shell.nix ./templates + ./lib ]; } diff --git a/parts/fmt.nix b/parts/fmt.nix index cb3ae37..1ab2e06 100644 --- a/parts/fmt.nix +++ b/parts/fmt.nix @@ -1,4 +1,5 @@ -{ +{inputs, ...}: { + imports = [inputs.treefmt-nix.flakeModule]; perSystem = { config, pkgs, @@ -15,7 +16,7 @@ programs = { alejandra.enable = true; - shellcheck.enable = true; # cannot be configured, errors on basic bash convention + shellcheck.enable = true; prettier = { enable = true; diff --git a/parts/lib/builders.nix b/parts/lib/builders.nix new file mode 100644 index 0000000..301e70e --- /dev/null +++ b/parts/lib/builders.nix @@ -0,0 +1,31 @@ +{ + lib, + inputs, + self, + ... +}: { + mkSystem = { + withSystem, + system, + ... + } @ args: + withSystem system ( + { + inputs', + self', + ... + }: + lib.nixosSystem { + inherit system; + specialArgs = + lib.recursiveUpdate + { + inherit lib; + inherit inputs inputs'; + inherit self self'; + } + (args.specialArgs or {}); + inherit (args) modules; + } + ); +} diff --git a/parts/lib/default.nix b/parts/lib/default.nix new file mode 100644 index 0000000..b6c5fe6 --- /dev/null +++ b/parts/lib/default.nix @@ -0,0 +1,17 @@ +{ + inputs, + lib, + self, + ... +}: let + callLibs = path: import path {inherit inputs lib self;}; + sussyLib = inputs.nixpkgs.lib.extend (final: prev: { + builders = callLibs ./builders.nix; + }); +in { + flake = { + lib = sussyLib; + # raf what the hell does this do you made me set it + _module.args.lib = sussyLib; + }; +} diff --git a/parts/lib/systemd.nix b/parts/lib/systemd.nix new file mode 100644 index 0000000..e69de29 diff --git a/parts/pre-commit/default.nix b/parts/pre-commit/default.nix deleted file mode 100644 index 6c107b4..0000000 --- a/parts/pre-commit/default.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ - perSystem = _: { - pre-commit = { - settings = { - excludes = ["flake.lock"]; - hooks = { - alejandra.enable = true; - prettier.enable = true; - }; - }; - }; - }; -} diff --git a/parts/shell.nix b/parts/shell.nix index cf5a11d..d49189b 100644 --- a/parts/shell.nix +++ b/parts/shell.nix @@ -9,9 +9,9 @@ DIRENV_LOG_FORMAT = ""; - # inputsFrom = [config.treefmt.build.devShell]; + inputsFrom = [config.treefmt.build.devShell]; packages = [ - # config.treefmt.build.wrapper # treewide formatter + config.treefmt.build.wrapper # treewide formatter pkgs.git # take a guess (pkgs.writeShellApplication { @@ -20,12 +20,6 @@ nix flake update && git commit flake.lock -m "flake: bump inputs" ''; }) - (pkgs.writeShellApplication { - name = "rebuild"; - text = '' - nh os switch - ''; - }) ]; }; };