From bd88d8382c70f6a5b0e8518d78fb64af2172a9f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Thu, 11 May 2023 21:48:38 +0200 Subject: [PATCH] refactor(flake): hand roll flake --- flake.lock | 23 +---- flake.nix | 152 +++++++++++++++++++-------------- hosts/nixos-desktop/system.nix | 1 + hosts/nixos-laptop/system.nix | 1 + overlays/channels.nix | 12 --- 5 files changed, 89 insertions(+), 100 deletions(-) create mode 100644 hosts/nixos-desktop/system.nix create mode 100644 hosts/nixos-laptop/system.nix delete mode 100644 overlays/channels.nix diff --git a/flake.lock b/flake.lock index 3577110..b514e2c 100644 --- a/flake.lock +++ b/flake.lock @@ -980,8 +980,7 @@ "nvim-treesitter-textsubjects": "nvim-treesitter-textsubjects", "pre-commit-hooks": "pre-commit-hooks", "smartcolumn-nvim": "smartcolumn-nvim", - "stable": "stable", - "utils": "utils" + "stable": "stable" } }, "rust-overlay": { @@ -1083,26 +1082,6 @@ "type": "github" } }, - "utils": { - "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" - } - }, "wlroots": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index e5115ea..dde8687 100644 --- a/flake.nix +++ b/flake.nix @@ -13,8 +13,6 @@ stable.url = "github:nixos/nixpkgs/nixos-22.11"; flake-utils.url = "github:numtide/flake-utils"; - utils.url = "github:gytis-ivaskevicius/flake-utils-plus"; - utils.inputs.flake-utils.follows = "flake-utils"; agenix.inputs.nixpkgs.follows = "nixpkgs"; agenix.url = "github:ryantm/agenix"; @@ -79,50 +77,51 @@ ║ Outputs ║ ╚══════════════════════════════════════════════════════════╝ */ - outputs = - inputs@{ self, nixpkgs, utils, ... }: - utils.lib.mkFlake { - inherit self inputs; + outputs = inputs@{ self, nixpkgs, ... }: + let + systems = [ "x86_64-linux" "aarch64-linux" ]; - supportedSystems = [ "x86_64-linux" ]; - - channelsConfig.allowUnfree = true; + forEachSystem = lib.genAttrs systems; lib = nixpkgs.lib.extend (self: _: { my = import ./lib { lib = self; }; }); - /* - ╔══════════════════════════════════════════════════════════╗ - ║ Overlays ║ - ╚══════════════════════════════════════════════════════════╝ - */ overlay = import ./overlays { inherit inputs; inherit (self) lib; }; - channels.nixpkgs.overlaysBuilder = _: [ + config.allowUnfree = true; + + overlays = [ inputs.hypr-contrib.overlays.default inputs.hyprland.overlays.default inputs.neovim-nightly-overlay.overlay - inputs.utils.overlay - self.overlay + overlay ]; - overlays = utils.lib.exportOverlays - { - inherit (self) pkgs inputs; - } // { - default = self.overlay; + pkgsFor = system: import nixpkgs { + inherit system config; + overlays = overlays ++ [ + ( + _: prev: { + master = import inputs.master { + inherit (prev) system; + inherit overlays config; + }; + stable = import inputs.stable { + inherit (prev) system; + inherit overlays config; + }; + } + ) + overlay + ]; }; - /* - ╔══════════════════════════════════════════════════════════╗ - ║ Modules ║ - ╚══════════════════════════════════════════════════════════╝ - */ - hostDefaults.modules = [ - ./modules/default.nix + defaultModules = [ + { nixpkgs = { inherit config; }; } + ./modules inputs.home-manager.nixosModule { home-manager = { @@ -134,45 +133,66 @@ inputs.agenix.nixosModules.age ]; - - hosts.nixos-laptop.modules = [ - ./hosts/nixos-laptop - ]; - - - hosts.nixos-desktop.modules = [ - ./hosts/nixos-desktop - ]; - - /* - ╔══════════════════════════════════════════════════════════╗ - ║ Other Outputs ║ - ╚══════════════════════════════════════════════════════════╝ - */ - outputsBuilder = channels: - with channels.nixpkgs; { - devShells.default = mkShell { - inherit (self.checks.${system}.pre-commit-check) shellHook; - name = "dotfiles"; - packages = [ - # Secrets - pkgs.agenix - # cachix - cachix - ]; - }; - - checks.pre-commit-check = inputs.pre-commit-hooks.lib."${system}".run { - src = ./.; - hooks = { - nixpkgs-fmt.enable = true; - statix.enable = true; - shellcheck.enable = true; - stylua.enable = true; + hosts = self.lib.my.mapModules + (path: + let + system = import "${path}/system.nix"; + pkgs = pkgsFor system; + in + lib.nixosSystem { + inherit pkgs system lib; + specialArgs = { + inherit inputs; }; - }; + modules = defaultModules ++ [ path ]; + }) + ./hosts; - packages = utils.lib.exportPackages self.overlays channels; + pre-commit-check = system: inputs.pre-commit-hooks.lib."${system}".run { + src = ./.; + hooks = { + nixpkgs-fmt.enable = true; + statix.enable = true; + shellcheck.enable = true; + stylua.enable = true; }; + }; + in + with lib; { + inherit lib; + + pkgs = genAttrs systems pkgsFor; + + # ╔══════════════════════════════════════════════════════════╗ + # ║ NixOS Configurations ║ + # ╚══════════════════════════════════════════════════════════╝ + + nixosConfigurations = hosts; + + # ╔══════════════════════════════════════════════════════════╗ + # ║ Other Outputs ║ + # ╚══════════════════════════════════════════════════════════╝ + + devShells = forEachSystem (system: + let + pkgs = pkgsFor system; + in + { + default = pkgs.mkShell + { + inherit (pre-commit-check system) shellHook; + name = "dotfiles"; + packages = with pkgs; [ + # Secrets + agenix + # cachix + cachix + ]; + }; + }); + + checks = forEachSystem (system: { + pre-commit-check = pre-commit-check system; + }); }; } diff --git a/hosts/nixos-desktop/system.nix b/hosts/nixos-desktop/system.nix new file mode 100644 index 0000000..132026a --- /dev/null +++ b/hosts/nixos-desktop/system.nix @@ -0,0 +1 @@ +"x86_64-linux" diff --git a/hosts/nixos-laptop/system.nix b/hosts/nixos-laptop/system.nix new file mode 100644 index 0000000..132026a --- /dev/null +++ b/hosts/nixos-laptop/system.nix @@ -0,0 +1 @@ +"x86_64-linux" diff --git a/overlays/channels.nix b/overlays/channels.nix deleted file mode 100644 index 5c2a49a..0000000 --- a/overlays/channels.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ inputs, ... }: - -_: prev: { - master = import inputs.master { - inherit (prev) system; - config.allowUnfree = true; - }; - stable = import inputs.stable { - inherit (prev) system; - config.allowUnfree = true; - }; -}