From 07e54f5b3c84885d2fef13e6959117aa29346322 Mon Sep 17 00:00:00 2001 From: seth Date: Sat, 16 Dec 2023 18:38:36 -0500 Subject: [PATCH] feat: add subflake for development & testing (#64) --- .github/workflows/format.yml | 10 +++-- .github/workflows/test-vm.yml | 5 ++- .github/workflows/update-docs.yml | 3 +- .github/workflows/update-lock.yml | 4 +- dev/flake.lock | 63 ++++++++++++++++++++++++++++ dev/flake.nix | 66 ++++++++++++++++++++++++++++++ flake.lock | 47 --------------------- flake.nix | 68 ++----------------------------- test.nix | 6 +-- 9 files changed, 151 insertions(+), 121 deletions(-) create mode 100644 dev/flake.lock create mode 100644 dev/flake.nix delete mode 100644 flake.lock diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 3bcc3d4..238d3ed 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -11,10 +11,14 @@ jobs: steps: - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v23 - with: - github_access_token: ${{ secrets.GITHUB_TOKEN }} + - name: Run formatter - run: nix fmt + run: | + pushd dev/ + nix fmt + popd + - name: Check for changes run: git diff --color=always --exit-code diff --git a/.github/workflows/test-vm.yml b/.github/workflows/test-vm.yml index a81ea2a..0140fd8 100644 --- a/.github/workflows/test-vm.yml +++ b/.github/workflows/test-vm.yml @@ -19,10 +19,13 @@ jobs: steps: - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v23 with: extra_nix_config: "system-features = benchmark big-parallel kvm nixos-test uid-range" + - uses: DeterminateSystems/magic-nix-cache-action@main - name: Run VM - run: nix build -Lv .#checks.x86_64-linux.module-vm-test + run: | + nix build -Lv ./dev#checks.x86_64-linux.module-vm-test diff --git a/.github/workflows/update-docs.yml b/.github/workflows/update-docs.yml index 4d7c993..7d28385 100644 --- a/.github/workflows/update-docs.yml +++ b/.github/workflows/update-docs.yml @@ -32,7 +32,8 @@ jobs: echo "rev=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" - name: Build doc - run: nix build .#${{ matrix.package }}-doc + run: | + nix build ./dev#${{ matrix.package }}-doc - name: Update doc run: cat result > docs/${{ matrix.package }}-options.md diff --git a/.github/workflows/update-lock.yml b/.github/workflows/update-lock.yml index 7ec55c9..5a5afcb 100644 --- a/.github/workflows/update-lock.yml +++ b/.github/workflows/update-lock.yml @@ -21,8 +21,10 @@ jobs: - name: Update flake inputs run: | + pushd dev nix flake update \ - --commit-lock-file --commit-lockfile-summary "chore: update flake inputs" + --commit-lock-file --commit-lockfile-summary "chore: update dev flake inputs" + popd - name: Update upstream sources run: | diff --git a/dev/flake.lock b/dev/flake.lock new file mode 100644 index 0000000..a9528cb --- /dev/null +++ b/dev/flake.lock @@ -0,0 +1,63 @@ +{ + "nodes": { + "call-flake": { + "locked": { + "lastModified": 1699147280, + "narHash": "sha256-bmhE1TmrJG4ba93l9WQTLuYM53kwGQAjYHRvHOeuxWU=", + "owner": "divnix", + "repo": "call-flake", + "rev": "7d993ee93bd35a9e6574ec76d54b7d44087495ad", + "type": "github" + }, + "original": { + "owner": "divnix", + "repo": "call-flake", + "type": "github" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1699368917, + "narHash": "sha256-nUtGIWf86BOkUbtksWtfglvCZ/otP0FTZlQH8Rzc7PA=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "6a8444467c83c961e2f5ff64fb4f422e303c98d3", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1699099776, + "narHash": "sha256-X09iKJ27mGsGambGfkKzqvw5esP1L/Rf8H3u3fCqIiU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "85f1ba3e51676fa8cc604a3d863d729026a6b8eb", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "call-flake": "call-flake", + "home-manager": "home-manager", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/dev/flake.nix b/dev/flake.nix new file mode 100644 index 0000000..0c20719 --- /dev/null +++ b/dev/flake.nix @@ -0,0 +1,66 @@ +{ + description = "Soothing pastel theme for Nix"; + + inputs = { + nixpkgs.url = "nixpkgs/nixos-unstable"; + + home-manager = { + url = "github:nix-community/home-manager"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + call-flake.url = "github:divnix/call-flake"; + }; + + outputs = { self, nixpkgs, call-flake, ... }@inputs: + let + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + + inherit (nixpkgs) lib; + + forAllSystems = fn: lib.genAttrs systems (s: fn nixpkgs.legacyPackages.${s}); + ctp = call-flake ../.; + in + { + checks = forAllSystems (pkgs: lib.optionalAttrs pkgs.stdenv.isLinux { + module-vm-test = pkgs.nixosTest (import ../test.nix { inherit ctp inputs; }); + }); + + formatter = forAllSystems (pkgs: pkgs.nixpkgs-fmt); + + packages = forAllSystems (pkgs: + let + eval = module: lib.evalModules { + modules = [ + module + { + _module.check = false; + } + ]; + }; + + mkDoc = name: module: + let + doc = pkgs.nixosOptionsDoc { + options = lib.filterAttrs (n: _: n != "_module") (eval module).options; + documentType = "none"; + revision = builtins.substring 0 8 self.rev or "dirty"; + }; + in + pkgs.runCommand "${name}-module-doc.md" { } '' + cat ${doc.optionsCommonMark} > $out + ''; + in + { + nixos-doc = mkDoc "nixos" ctp.nixosModules.catppuccin; + home-manager-doc = mkDoc "home-manager" ctp.homeManagerModules.catppuccin; + + default = self.packages.${pkgs.system}.home-manager-doc; + }); + }; +} diff --git a/flake.lock b/flake.lock deleted file mode 100644 index 7423a05..0000000 --- a/flake.lock +++ /dev/null @@ -1,47 +0,0 @@ -{ - "nodes": { - "home-manager": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1698873617, - "narHash": "sha256-FfGFcfbULwbK1vD+H0rslIOfmy4g8f2hXiPkQG3ZCTk=", - "owner": "nix-community", - "repo": "home-manager", - "rev": "48b0a30202516e25d9885525fbb200a045f23f26", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "home-manager", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1698611440, - "narHash": "sha256-jPjHjrerhYDy3q9+s5EAsuhyhuknNfowY6yt6pjn9pc=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "0cbe9f69c234a7700596e943bfae7ef27a31b735", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "ref": "nixos-unstable", - "type": "indirect" - } - }, - "root": { - "inputs": { - "home-manager": "home-manager", - "nixpkgs": "nixpkgs" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/flake.nix b/flake.nix index 97ce08a..e5bac3b 100644 --- a/flake.nix +++ b/flake.nix @@ -1,70 +1,8 @@ { description = "Soothing pastel theme for Nix"; - inputs = { - nixpkgs.url = "nixpkgs/nixos-unstable"; - - home-manager = { - url = "github:nix-community/home-manager"; - inputs.nixpkgs.follows = "nixpkgs"; - }; + outputs = _: { + homeManagerModules.catppuccin = import ./modules/home-manager; + nixosModules.catppuccin = import ./modules/nixos; }; - - outputs = { self, nixpkgs, ... }@inputs: - let - systems = [ - "x86_64-linux" - "aarch64-linux" - "x86_64-darwin" - "aarch64-darwin" - ]; - - inherit (nixpkgs) lib; - - forAllSystems = fn: lib.genAttrs systems (s: fn nixpkgs.legacyPackages.${s}); - in - { - checks = forAllSystems (pkgs: lib.optionalAttrs pkgs.stdenv.isLinux { - module-vm-test = pkgs.nixosTest (import ./test.nix { inherit self inputs; }); - }); - - formatter = forAllSystems (pkgs: pkgs.nixpkgs-fmt); - - homeManagerModules.catppuccin = import ./modules/home-manager; - - nixosModules.catppuccin = import ./modules/nixos; - - packages = forAllSystems (pkgs: - let - eval = module: lib.evalModules { - modules = [ - module - { - _module = { - check = false; - args.lib = import ./modules/lib/mkExtLib.nix lib; - }; - } - ]; - }; - - mkDoc = name: module: - let - doc = pkgs.nixosOptionsDoc { - options = lib.filterAttrs (n: _: n != "_module") (eval module).options; - documentType = "none"; - revision = builtins.substring 0 8 self.rev or "dirty"; - }; - in - pkgs.runCommand "${name}-module-doc.md" { } '' - cat ${doc.optionsCommonMark} > $out - ''; - in - { - nixos-doc = mkDoc "nixos" self.nixosModules.catppuccin; - home-manager-doc = mkDoc "home-manager" self.homeManagerModules.catppuccin; - - default = self.packages.${pkgs.system}.home-manager-doc; - }); - }; } diff --git a/test.nix b/test.nix index f341e55..57f8bf4 100644 --- a/test.nix +++ b/test.nix @@ -1,4 +1,4 @@ -{ self +{ ctp , inputs , ... }: @@ -21,7 +21,7 @@ in nodes.machine = { lib, ... }: { imports = [ - self.nixosModules.catppuccin + ctp.nixosModules.catppuccin inputs.home-manager.nixosModules.default common ]; @@ -37,7 +37,7 @@ in home-manager.users.test = { imports = [ - self.homeManagerModules.catppuccin + ctp.homeManagerModules.catppuccin ]; inherit (common) catppuccin;