diff options
| -rw-r--r-- | .envrc | 11 | ||||
| -rw-r--r-- | flake.lock | 23 | ||||
| -rw-r--r-- | flake.nix | 268 | ||||
| -rw-r--r-- | flake/checks.nix | 42 | ||||
| -rw-r--r-- | flake/devshells.nix | 61 | ||||
| -rw-r--r-- | flake/formatter.nix | 17 | ||||
| -rw-r--r-- | flake/hosts.nix | 163 | ||||
| -rw-r--r-- | flake/overlays.nix | 24 |
8 files changed, 255 insertions, 354 deletions
@@ -1,12 +1 @@ use flake - -watch_file flake/checks.nix -watch_file flake/devshells.nix -watch_file flake/formatter.nix -watch_file flake/hosts.nix -watch_file flake/overlays.nix - -watch_file scripts/common.nix -watch_file scripts/darwin.nix -watch_file scripts/default.nix -watch_file scripts/linux.nix @@ -142,26 +142,6 @@ "flake-parts": { "inputs": { "nixpkgs-lib": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1762980239, - "narHash": "sha256-8oNVE8TrD19ulHinjaqONf9QWCKK+w4url56cdStMpM=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "52a2caecc898d0b46b2b905f058ccc5081f842da", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, - "flake-parts_2": { - "inputs": { - "nixpkgs-lib": [ "nur", "nixpkgs" ] @@ -366,7 +346,7 @@ }, "nur": { "inputs": { - "flake-parts": "flake-parts_2", + "flake-parts": "flake-parts", "nixpkgs": [ "nixpkgs" ] @@ -436,7 +416,6 @@ "darwin": "darwin_2", "disko": "disko", "emacs-overlay": "emacs-overlay", - "flake-parts": "flake-parts", "home-manager": "home-manager_2", "my-go-tools": "my-go-tools", "nixos-hardware": "nixos-hardware", @@ -48,28 +48,268 @@ inputs.nixpkgs.follows = "nixpkgs"; }; - flake-parts = { - url = "github:hercules-ci/flake-parts"; - inputs.nixpkgs-lib.follows = "nixpkgs"; - }; - my-go-tools.url = "git+https://code.fcuny.net/x"; }; outputs = - inputs@{ flake-parts, ... }: - flake-parts.lib.mkFlake { inherit inputs; } { - systems = [ + inputs@{ + self, + nixpkgs, + darwin, + home-manager, + disko, + agenix, + treefmt-nix, + pre-commit-hooks, + emacs-overlay, + nur, + my-go-tools, + ... + }: + let + supportedSystems = [ "aarch64-darwin" "x86_64-linux" ]; - imports = [ - ./flake/checks.nix - ./flake/devshells.nix - ./flake/formatter.nix - ./flake/hosts.nix - ./flake/overlays.nix + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + + pkgsFor = + system: + import nixpkgs { + inherit system; + config.allowUnfree = true; + overlays = [ + self.overlays.default + agenix.overlays.default + emacs-overlay.overlay + nur.overlays.default + my-go-tools.overlays.default + ]; + }; + + nixSettings = { + nix.registry.nixpkgs = { + flake = nixpkgs; + }; + }; + + defaultModules = [ + nixSettings + agenix.nixosModules.age + disko.nixosModules.disko + home-manager.nixosModules.home-manager + ./modules/default.nix ]; + + # Default modules for Darwin hosts + darwinDefaultModules = [ + nixSettings + agenix.darwinModules.age + home-manager.darwinModules.home-manager + ./modules/default-darwin.nix + ]; + + machines = { + nixos = { + rivendell = { + system = "x86_64-linux"; + config = ./machines/nixos/x86_64-linux/rivendell.nix; + }; + bree = { + system = "x86_64-linux"; + config = ./machines/nixos/x86_64-linux/bree.nix; + }; + argonath = { + system = "x86_64-linux"; + config = ./machines/nixos/x86_64-linux/argonath.nix; + }; + iso = { + system = "x86_64-linux"; + config = ./machines/nixos/x86_64-linux/iso.nix; + }; + }; + darwin = { + mba-m2 = { + system = "aarch64-darwin"; + config = ./machines/darwin/aarch64-darwin/mba-m2.nix; + }; + HQ-KWNY2VH41P = { + system = "aarch64-darwin"; + config = ./machines/darwin/aarch64-darwin/HQ-KWNY2VH41P.nix; + }; + }; + }; + + nixosConfigurations = nixpkgs.lib.mapAttrs ( + name: machine: + let + pkgs = pkgsFor machine.system; + in + nixpkgs.lib.nixosSystem { + inherit (machine) system; + specialArgs = { + hostName = name; + inherit self inputs; + hostConfigurations = nixpkgs.lib.mapAttrs (_: conf: conf.config) nixosConfigurations; + }; + modules = [ + { + system.configurationRevision = nixpkgs.lib.mkIf (self ? rev) self.rev; + system.nixos.versionSuffix = nixpkgs.lib.mkForce "git.${builtins.substring 0 11 nixpkgs.rev}"; + nixpkgs.pkgs = pkgs; + environment.systemPackages = [ pkgs.git ]; + } + ] + ++ defaultModules + ++ [ + machine.config + my-go-tools.nixosModules.default + ]; + } + ) machines.nixos; + + darwinConfigurations = nixpkgs.lib.mapAttrs ( + name: machine: + let + pkgs = pkgsFor machine.system; + in + darwin.lib.darwinSystem { + inherit (machine) system; + specialArgs = { + hostName = name; + inherit self inputs; + }; + modules = [ + { + nixpkgs.pkgs = pkgs; + nixpkgs.hostPlatform = machine.system; + system.stateVersion = 5; + environment.systemPackages = [ pkgs.git ]; + } + ] + ++ darwinDefaultModules + ++ [ machine.config ]; + } + ) machines.darwin; + in + { + # Host configurations + inherit nixosConfigurations darwinConfigurations; + + # Overlays + overlays.default = _final: prev: { + sapi = prev.callPackage ./pkgs/sapi { }; + hashi = prev.callPackage ./pkgs/hashi { }; + }; + + devShells = forAllSystems ( + system: + let + pkgs = pkgsFor system; + + # Treefmt configuration + treefmtEval = treefmt-nix.lib.evalModule pkgs { + projectRootFile = "flake.nix"; + programs = { + nixfmt.enable = true; + deadnix.enable = true; + }; + }; + + # Pre-commit hooks + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + check-merge-conflicts.enable = true; + deadnix.enable = true; + detect-private-keys.enable = true; + end-of-file-fixer.enable = true; + mixed-line-endings.enable = true; + shellcheck = { + enable = true; + excludes = [ "\\.envrc$" ]; + }; + flake-checker.enable = true; + treefmt = { + enable = true; + entry = "${treefmtEval.config.build.wrapper}/bin/treefmt --ci"; + }; + trim-trailing-whitespace.enable = true; + }; + }; + + # Import any custom scripts + scripts = import ./flake/scripts { + inherit pkgs system inputs; + }; + in + { + default = pkgs.mkShellNoCC { + inherit (pre-commit-check) shellHook; + packages = + with pkgs; + [ + nixos-rebuild + git + agenix.packages."${system}".default + ] + ++ scripts.all; + }; + } + ); + formatter = forAllSystems ( + system: + let + pkgs = pkgsFor system; + treefmtEval = treefmt-nix.lib.evalModule pkgs { + projectRootFile = "flake.nix"; + programs = { + nixfmt.enable = true; + deadnix.enable = true; + }; + }; + in + treefmtEval.config.build.wrapper + ); + + checks = forAllSystems ( + system: + let + pkgs = pkgsFor system; + + treefmtEval = treefmt-nix.lib.evalModule pkgs { + projectRootFile = "flake.nix"; + programs = { + nixfmt.enable = true; + deadnix.enable = true; + }; + }; + + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + check-merge-conflicts.enable = true; + deadnix.enable = true; + detect-private-keys.enable = true; + end-of-file-fixer.enable = true; + mixed-line-endings.enable = true; + shellcheck = { + enable = true; + excludes = [ "\\.envrc$" ]; + }; + flake-checker.enable = true; + treefmt = { + enable = true; + entry = "${treefmtEval.config.build.wrapper}/bin/treefmt --ci"; + }; + trim-trailing-whitespace.enable = true; + }; + }; + in + { + inherit pre-commit-check; + } + ); }; } diff --git a/flake/checks.nix b/flake/checks.nix deleted file mode 100644 index 87d4a7f..0000000 --- a/flake/checks.nix +++ /dev/null @@ -1,42 +0,0 @@ -{ inputs, ... }: -{ - perSystem = - { system, pkgs, ... }: - let - treefmtEval = inputs.treefmt-nix.lib.evalModule pkgs { - projectRootFile = "flake.nix"; - programs = { - nixfmt.enable = true; - deadnix.enable = true; - }; - }; - - mkPreCommitHooks = - src: - inputs.pre-commit-hooks.lib.${system}.run { - inherit src; - hooks = { - check-merge-conflicts.enable = true; - deadnix.enable = true; - detect-private-keys.enable = true; - end-of-file-fixer.enable = true; - mixed-line-endings.enable = true; - shellcheck = { - enable = true; - excludes = [ "\\.envrc$" ]; - }; - flake-checker.enable = true; - treefmt = { - enable = true; - entry = "${treefmtEval.config.build.wrapper}/bin/treefmt --ci"; - }; - trim-trailing-whitespace.enable = true; - }; - }; - in - { - checks = { - pre-commit-check = mkPreCommitHooks ./.; - }; - }; -} diff --git a/flake/devshells.nix b/flake/devshells.nix deleted file mode 100644 index a2d6a9d..0000000 --- a/flake/devshells.nix +++ /dev/null @@ -1,61 +0,0 @@ -{ self, inputs, ... }: -{ - perSystem = - { system, pkgs, ... }: - let - treefmtEval = inputs.treefmt-nix.lib.evalModule pkgs { - projectRootFile = "flake.nix"; - programs = { - nixfmt.enable = true; - deadnix.enable = true; - }; - }; - - mkPreCommitHooks = - src: - inputs.pre-commit-hooks.lib.${system}.run { - inherit src; - hooks = { - check-merge-conflicts.enable = true; - deadnix.enable = true; - detect-private-keys.enable = true; - end-of-file-fixer.enable = true; - mixed-line-endings.enable = true; - shellcheck = { - enable = true; - excludes = [ "\\.envrc$" ]; - }; - flake-checker.enable = true; - treefmt = { - enable = true; - entry = "${treefmtEval.config.build.wrapper}/bin/treefmt --ci"; - }; - trim-trailing-whitespace.enable = true; - }; - }; - - pre-commit-check = mkPreCommitHooks ./.; - scripts = import "${self}/flake/scripts" { - inherit - pkgs - system - inputs - ; - }; - in - { - devShells = { - default = pkgs.mkShellNoCC { - inherit (pre-commit-check) shellHook; - packages = - with pkgs; - [ - nixos-rebuild - git - inputs.agenix.packages."${system}".default - ] - ++ scripts.all; - }; - }; - }; -} diff --git a/flake/formatter.nix b/flake/formatter.nix deleted file mode 100644 index 44c0190..0000000 --- a/flake/formatter.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ inputs, ... }: -{ - perSystem = - { pkgs, ... }: - let - treefmtEval = inputs.treefmt-nix.lib.evalModule pkgs { - projectRootFile = "flake.nix"; - programs = { - nixfmt.enable = true; - deadnix.enable = true; - }; - }; - in - { - formatter = treefmtEval.config.build.wrapper; - }; -} diff --git a/flake/hosts.nix b/flake/hosts.nix deleted file mode 100644 index 88be6dc..0000000 --- a/flake/hosts.nix +++ /dev/null @@ -1,163 +0,0 @@ -{ - inputs, - self, - withSystem, - ... -}: -let - inherit (inputs.nixpkgs.lib // builtins) - filterAttrs - foldl' - makeOverridable - mapAttrs' - mapAttrsToList - mkForce - mkIf - nixosSystem - readDir - replaceStrings - substring - ; - - inherit (inputs.darwin.lib) darwinSystem; - - nixSettings = { - nix.registry.nixpkgs = { - flake = inputs.nixpkgs; - }; - }; - - mapSystems = - dir: mapAttrsToList (name: _: name) (filterAttrs (_: type: type == "directory") (readDir dir)); - - mapHosts = foldl' ( - hosts: system: - hosts - // (mapAttrs' ( - filename: _: - let - name = replaceStrings [ ".nix" ] [ "" ] filename; - in - { - inherit name; - value = { - inherit system; - hostconf = "${self}/machines/nixos/${system}/${filename}"; - }; - } - ) (builtins.readDir "${self}/machines/nixos/${system}")) - ) { }; - - mapMacs = foldl' ( - hosts: system: - hosts - // (mapAttrs' ( - filename: _: - let - name = replaceStrings [ ".nix" ] [ "" ] filename; - in - { - inherit name; - value = { - inherit system; - hostconf = "${self}/machines/darwin/${system}/${filename}"; - }; - } - ) (builtins.readDir "${self}/machines/darwin/${system}")) - ) { }; - - defaultModules = [ - nixSettings - inputs.agenix.nixosModules.age - inputs.disko.nixosModules.disko - inputs.home-manager.nixosModules.home-manager - ../modules/default.nix - ]; - - darwinDefaultModules = [ - nixSettings - inputs.agenix.darwinModules.age - inputs.home-manager.darwinModules.home-manager - ../modules/default-darwin.nix - ]; - - darwinConfigurations = mapAttrs' ( - name: conf: - let - inherit (conf) system hostconf; - in - { - inherit name; - value = withSystem system ( - { pkgs, ... }: - makeOverridable darwinSystem { - inherit system; - specialArgs = { - hostName = name; - inherit self; - inherit inputs; - }; - modules = [ - { - nixpkgs.pkgs = pkgs; - nixpkgs.hostPlatform = system; - system.stateVersion = 5; - environment.systemPackages = [ - pkgs.git - ]; - } - ] - ++ darwinDefaultModules - ++ [ - hostconf - ]; - } - ); - } - ) (mapMacs (mapSystems ../machines/darwin)); - - nixosConfigurations = mapAttrs' ( - name: conf: - let - inherit (conf) system hostconf; - in - { - inherit name; - value = withSystem system ( - { pkgs, ... }: - makeOverridable nixosSystem { - inherit system; - specialArgs = { - hostName = name; - inherit self; - hostConfigurations = mapAttrs' (name: conf: { - inherit name; - value = conf.config; - }) nixosConfigurations; - inherit inputs; - }; - modules = [ - { - system.configurationRevision = mkIf (self ? rev) self.rev; - system.nixos.versionSuffix = mkForce "git.${substring 0 11 inputs.nixpkgs.rev}"; - nixpkgs.pkgs = pkgs; - environment.systemPackages = [ - pkgs.git - ]; - } - ] - ++ defaultModules - ++ [ - hostconf - inputs.my-go-tools.nixosModules.default - ]; - } - ); - } - ) (mapHosts (mapSystems ../machines/nixos)); -in -{ - flake = { - inherit nixosConfigurations darwinConfigurations; - }; -} diff --git a/flake/overlays.nix b/flake/overlays.nix deleted file mode 100644 index 1eecfcf..0000000 --- a/flake/overlays.nix +++ /dev/null @@ -1,24 +0,0 @@ -{ inputs, self, ... }: -{ - - flake.overlays.default = _final: prev: { - sapi = prev.callPackage "${self}/pkgs/sapi" { }; - hashi = prev.callPackage "${self}/pkgs/hashi" { }; - }; - - perSystem = - { system, ... }: - { - _module.args.pkgs = import inputs.nixpkgs { - inherit system; - config.allowUnfree = true; - overlays = [ - inputs.agenix.overlays.default - inputs.emacs-overlay.overlay - inputs.nur.overlays.default - inputs.my-go-tools.overlays.default - self.overlays.default - ]; - }; - }; -} |
