diff --git a/checks.nix b/checks.nix new file mode 100644 index 0000000..77c0c15 --- /dev/null +++ b/checks.nix @@ -0,0 +1,15 @@ +{ + self, + flake-utils, + git-hooks, + ... +}: +flake-utils.lib.eachDefaultSystem (system: { + checks.pre-commit-check = git-hooks.lib.${system}.run { + src = ./.; # TODO: self? + hooks.treefmt = { + enable = true; + package = self.packages.${system}.formatter; + }; + }; +}) diff --git a/colmena.nix b/colmena.nix new file mode 100644 index 0000000..588d476 --- /dev/null +++ b/colmena.nix @@ -0,0 +1,41 @@ +inputs @ { + self, + nixpkgs, + ... +}: { + colmena = { + meta = { + nixpkgs = import nixpkgs { + system = "x86_64-linux"; + }; + + specialArgs = { + inherit inputs self; + }; + }; + + sue = { + deployment = { + allowLocalDeployment = true; + targetHost = null; + }; + + imports = [ + (import ./machines).sue.module + ./nixos + ]; + }; + + gamepc = { + deployment = { + targetHost = "gamepc"; + targetUser = "root"; + }; + + imports = [ + (import ./machines).gamepc.module + ./nixos + ]; + }; + }; +} diff --git a/dev-shells.nix b/dev-shells.nix new file mode 100644 index 0000000..2d9ff4d --- /dev/null +++ b/dev-shells.nix @@ -0,0 +1,12 @@ +{ + self, + nixpkgs, + flake-utils, + ... +}: +flake-utils.lib.eachDefaultSystem (system: { + devShells.default = nixpkgs.legacyPackages.${system}.mkShell { + inherit (self.checks.${system}.pre-commit-check) shellHook; + buildInputs = self.checks.${system}.pre-commit-check.enabledPackages; + }; +}) diff --git a/flake.lock b/flake.lock index cc5b471..800d841 100644 --- a/flake.lock +++ b/flake.lock @@ -256,6 +256,24 @@ "inputs": { "systems": "systems" }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, "locked": { "lastModified": 1681202837, "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", @@ -416,7 +434,7 @@ "crane": "crane", "flake-compat": "flake-compat_2", "flake-parts": "flake-parts", - "flake-utils": "flake-utils", + "flake-utils": "flake-utils_2", "nixpkgs": [ "nixpkgs" ], @@ -689,6 +707,7 @@ "root": { "inputs": { "disko": "disko", + "flake-utils": "flake-utils", "git-hooks": "git-hooks", "home-manager": "home-manager", "lanzaboote": "lanzaboote", @@ -815,6 +834,21 @@ "type": "github" } }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "treefmt-nix": { "inputs": { "nixpkgs": "nixpkgs_4" diff --git a/flake.nix b/flake.nix index 443de49..262f27e 100644 --- a/flake.nix +++ b/flake.nix @@ -8,6 +8,7 @@ stylix.url = "github:pizzapim/stylix/release-24.05"; treefmt-nix.url = "github:numtide/treefmt-nix"; nixos-facter-modules.url = "github:numtide/nixos-facter-modules"; + flake-utils.url = "github:numtide/flake-utils"; git-hooks = { url = "github:cachix/git-hooks.nix"; @@ -51,110 +52,13 @@ }; }; - outputs = { - self, - nixpkgs, - ... - } @ inputs: let - supportedSystems = [ - "x86_64-linux" - "i686-linux" - "aarch64-linux" + outputs = inputs @ {flake-utils, ...}: + flake-utils.lib.meld inputs [ + ./packages.nix + ./formatter.nix + ./nixos-configurations.nix + ./checks.nix + ./dev-shells.nix + ./colmena.nix ]; - forAllSystems' = nixpkgs.lib.genAttrs; - forAllSystems = forAllSystems' supportedSystems; - pkgsForSystem = system: - import nixpkgs { - inherit system; - }; - - treefmtEval = forAllSystems ( - system: inputs.treefmt-nix.lib.evalModule (pkgsForSystem system) ./treefmt.nix - ); - in { - formatter = forAllSystems (system: (treefmtEval.${system}.config.build.wrapper)); - - nixosConfigurations = nixpkgs.lib.mapAttrs ( - name: nixosModule: - nixpkgs.lib.nixosSystem rec { - system = "x86_64-linux"; - - specialArgs = { - inherit inputs system self; - }; - - modules = [ - nixosModule - ./nixos - ]; - } - ) (import ./machines); - - checks = forAllSystems (system: { - pre-commit-check = inputs.git-hooks.lib.${system}.run { - src = ./.; - hooks = { - treefmt = { - enable = true; - package = treefmtEval.${system}.config.build.wrapper; - }; - }; - }; - }); - - devShells = forAllSystems (system: { - default = nixpkgs.legacyPackages.${system}.mkShell { - inherit (self.checks.${system}.pre-commit-check) shellHook; - buildInputs = self.checks.${system}.pre-commit-check.enabledPackages; - }; - }); - - colmena = { - meta = { - nixpkgs = import nixpkgs { - system = "x86_64-linux"; - }; - - specialArgs = { - inherit inputs self; - }; - - nodeSpecialArgs = { - sue = {}; - }; - }; - - sue = { - name, - nodes, - ... - }: { - deployment = { - allowLocalDeployment = true; - targetHost = null; - }; - - imports = [ - (import ./machines).sue - ./nixos - ]; - }; - - gamepc = { - name, - nodes, - ... - }: { - deployment = { - targetHost = "gamepc"; - targetUser = "root"; - }; - - imports = [ - (import ./machines).gamepc - ./nixos - ]; - }; - }; - }; } diff --git a/formatter.nix b/formatter.nix new file mode 100644 index 0000000..74ce5d3 --- /dev/null +++ b/formatter.nix @@ -0,0 +1,8 @@ +{ + self, + flake-utils, + ... +}: +flake-utils.lib.eachDefaultSystem (system: { + formatter = self.packages.${system}.formatter; +}) diff --git a/machines/default.nix b/machines/default.nix index 521f4dc..ec75d0d 100644 --- a/machines/default.nix +++ b/machines/default.nix @@ -1,4 +1,11 @@ { - sue = import ./sue; - gamepc = import ./gamepc; + sue = { + system = "x86_64-linux"; + module = import ./sue; + }; + + gamepc = { + system = "x86_64-linux"; + module = import ./gamepc; + }; } diff --git a/nixos-configurations.nix b/nixos-configurations.nix new file mode 100644 index 0000000..e2e8ff2 --- /dev/null +++ b/nixos-configurations.nix @@ -0,0 +1,17 @@ +inputs @ { + nixpkgs, + self, + ... +}: +nixpkgs.lib.mapAttrs (name: { + system, + module, + }: + nixpkgs.lib.nixosSystem { + inherit system; + modules = [./nixos module]; + + specialArgs = { + inherit inputs system self; + }; + }) (import ./machines) diff --git a/packages.nix b/packages.nix new file mode 100644 index 0000000..c5c5267 --- /dev/null +++ b/packages.nix @@ -0,0 +1,13 @@ +{ + nixpkgs, + flake-utils, + treefmt-nix, + ... +}: +flake-utils.lib.eachDefaultSystem (system: let + pkgs = nixpkgs.legacyPackages.${system}; + treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix; + treefmtWrapper = treefmtEval.config.build.wrapper; +in { + packages.formatter = treefmtWrapper; +})