diff --git a/.github/workflows/devshell.yaml b/.github/workflows/devshell.yaml new file mode 100644 index 0000000..6e1c80b --- /dev/null +++ b/.github/workflows/devshell.yaml @@ -0,0 +1,50 @@ +name: Dev Shell + +on: + push: + branches: [main] + paths: + - 'templates/**' + - '.github/workflows/devshell.yaml' + pull_request: + branches: [main] + paths: + - 'templates/**' + - '.github/workflows/devshell.yaml' + +jobs: + discover: + name: Discover templates + runs-on: ubuntu-24.04 + outputs: + templates: ${{ steps.list.outputs.templates }} + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + + - name: List templates + id: list + run: | + templates=$(ls -1 templates/ | jq -Rc '[.,inputs]') + echo "templates=$templates" >> "$GITHUB_OUTPUT" + + devshell-build: + name: Build devShell (${{ matrix.template }}) + needs: discover + runs-on: ubuntu-24.04 + strategy: + fail-fast: false + matrix: + template: ${{ fromJson(needs.discover.outputs.templates) }} + + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + + - uses: cachix/install-nix-action@616559265b40713947b9c190a8ff4b507b5df49b # v31 + + - uses: cachix/cachix-action@1eb2ef646ac0255473d23a5907ad7b04ce94065c # v17 + with: + name: rito528-dotfiles + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + + - name: Build devShell + run: nix build ./templates/${{ matrix.template }}#devShells.x86_64-linux.default diff --git a/README.md b/README.md index 0cd83fc..fda921b 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ dotfiles/ │ ├── lint.yaml # shellcheck・nixfmt Lint │ ├── integration-test.yaml # Cachix を使った home-manager ビルド検証 │ ├── nix.yaml # Nix flake check +│ ├── devshell.yaml # templates/ 配下の devShell ビルド検証 │ ├── nix-update-pr.yaml # Renovate 時のハッシュ自動更新 │ ├── update-flake-lock.yaml # 週次 flake.lock 更新 │ ├── e2e-setup-test.yaml # セットアップ E2E テスト @@ -137,32 +138,13 @@ home-manager generations ## 開発環境テンプレート -プロジェクトごとに独立した Nix 開発環境を提供するテンプレートを管理しています。 - -- `rust` -- `scala` -- `typescript` +プロジェクトごとに独立した Nix 開発環境を提供するテンプレートを管理しています(`templates/` 参照)。 ### 自分のプロジェクトで使う場合 ```bash -# プロジェクトディレクトリで初期化 -nix flake init -t github:rito528/dotfiles#rust -nix flake init -t github:rito528/dotfiles#scala -nix flake init -t github:rito528/dotfiles#typescript -``` - -### OSS プロジェクト等で dotfiles の devShell を直接参照する場合 - -```bash -# Rust 環境に入る -nix develop 'github:rito528/dotfiles#rust' - -# Scala 環境に入る -nix develop 'github:rito528/dotfiles#scala' - -# TypeScript 環境に入る -nix develop 'github:rito528/dotfiles#typescript' +# プロジェクトディレクトリで初期化(例) +nix flake init -t github:rito528/dotfiles#seichi-infra ``` ### direnv との連携 @@ -170,8 +152,13 @@ nix develop 'github:rito528/dotfiles#typescript' プロジェクトディレクトリに `.envrc` を作成することで、ディレクトリに入ると自動的に開発環境が有効になります: ```bash +# テンプレートで初期化したプロジェクトの場合 echo "use flake" > .envrc direnv allow + +# dotfiles のテンプレートを直接参照する場合 +echo "use flake 'github:rito528/dotfiles?dir=templates/rust'" > .envrc +direnv allow ``` > `.envrc` はプロジェクト固有の設定のため、global gitignore に追加することを推奨します。 diff --git a/flake.nix b/flake.nix index 8b742fa..036507a 100644 --- a/flake.nix +++ b/flake.nix @@ -7,17 +7,12 @@ url = "github:nix-community/home-manager"; inputs.nixpkgs.follows = "nixpkgs"; }; - rust-overlay = { - url = "github:oxalica/rust-overlay"; - inputs.nixpkgs.follows = "nixpkgs"; - }; }; outputs = { nixpkgs, home-manager, - rust-overlay, ... }: let @@ -31,10 +26,6 @@ "github-copilot-cli" ]; }; - pkgsWithRust = import nixpkgs { - inherit system; - overlays = [ rust-overlay.overlays.default ]; - }; mkHomeConfig = username: homeDirectory: personal: home-manager.lib.homeManagerConfiguration { @@ -62,7 +53,6 @@ ); npmPackages = loadPackagesDir ./modules/npm/packages; extraPackages = loadPackagesDir ./modules/packages; - mkShellWithZsh = mkPkgs: args: mkPkgs.mkShell ({ SHELL = "${pkgs.zsh}/bin/zsh"; } // args); in { packages.${system} = npmPackages // extraPackages; @@ -79,18 +69,6 @@ }; }; templates = { - rust = { - path = ./templates/rust; - description = "Rust development environment"; - }; - scala = { - path = ./templates/scala; - description = "Scala development environment"; - }; - typescript = { - path = ./templates/typescript; - description = "TypeScript (pnpm) development environment"; - }; seichi-assist = { path = ./templates/seichi-assist; description = "SeichiAssist development environment"; @@ -108,70 +86,5 @@ description = "seichi-portal-frontend development environment"; }; }; - devShells.${system} = { - rust = mkShellWithZsh pkgsWithRust { - buildInputs = [ - pkgsWithRust.rust-bin.stable.latest.default - pkgsWithRust.pkg-config - pkgsWithRust.openssl - ]; - }; - scala = mkShellWithZsh pkgs { - buildInputs = [ - pkgs.jdk17 - pkgs.sbt - pkgs.metals - pkgs.scalafmt - pkgs.stdenv.cc.cc.lib - ]; - shellHook = '' - export LD_LIBRARY_PATH="${pkgs.stdenv.cc.cc.lib}/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" - ''; - }; - typescript = mkShellWithZsh pkgs { - buildInputs = [ - pkgs.nodejs_22 - pkgs.pnpm - pkgs.typescript - pkgs.typescript-language-server - pkgs.vscode-langservers-extracted - ]; - }; - seichi-assist = mkShellWithZsh pkgs { - buildInputs = [ - pkgs.jdk17 - pkgs.sbt - pkgs.metals - pkgs.scalafmt - pkgs.stdenv.cc.cc.lib - ]; - shellHook = '' - export LD_LIBRARY_PATH="${pkgs.stdenv.cc.cc.lib}/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" - ''; - }; - seichi-infra = mkShellWithZsh pkgs { - buildInputs = [ - pkgs.terraform - pkgs.tflint - pkgs.kubectl - pkgs.kubernetes-helm - ]; - }; - seichi-portal-backend = mkShellWithZsh pkgsWithRust { - buildInputs = [ - pkgsWithRust.rust-bin.stable.latest.default - pkgsWithRust.pkg-config - pkgsWithRust.openssl - pkgsWithRust.cargo-make - pkgsWithRust.sqlx-cli - ]; - }; - seichi-portal-frontend = mkShellWithZsh pkgs { - buildInputs = [ - pkgs.nodejs_22 - pkgs.pnpm - ]; - }; - }; }; } diff --git a/templates/rust/.envrc b/templates/rust/.envrc deleted file mode 100644 index 3550a30..0000000 --- a/templates/rust/.envrc +++ /dev/null @@ -1 +0,0 @@ -use flake diff --git a/templates/rust/flake.nix b/templates/rust/flake.nix deleted file mode 100644 index 30367eb..0000000 --- a/templates/rust/flake.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ - description = "Rust development environment"; - - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - rust-overlay = { - url = "github:oxalica/rust-overlay"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - }; - - outputs = - { nixpkgs, rust-overlay, ... }: - let - system = "x86_64-linux"; - pkgs = import nixpkgs { - inherit system; - overlays = [ rust-overlay.overlays.default ]; - }; - in - { - devShells.${system}.default = pkgs.mkShell { - buildInputs = [ - pkgs.rust-bin.stable.latest.default - pkgs.pkg-config - pkgs.openssl - ]; - }; - }; -} diff --git a/templates/scala/.envrc b/templates/scala/.envrc deleted file mode 100644 index 3550a30..0000000 --- a/templates/scala/.envrc +++ /dev/null @@ -1 +0,0 @@ -use flake diff --git a/templates/scala/flake.nix b/templates/scala/flake.nix deleted file mode 100644 index c80b3cc..0000000 --- a/templates/scala/flake.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ - description = "Scala development environment"; - - inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - - outputs = - { nixpkgs, ... }: - let - system = "x86_64-linux"; - pkgs = import nixpkgs { inherit system; }; - in - { - devShells.${system}.default = pkgs.mkShell { - buildInputs = [ - pkgs.jdk17 - pkgs.sbt - pkgs.bloop - pkgs.metals - pkgs.scalafmt - ]; - }; - }; -} diff --git a/templates/seichi-infra/flake.nix b/templates/seichi-infra/flake.nix index 61138a9..dfebda4 100644 --- a/templates/seichi-infra/flake.nix +++ b/templates/seichi-infra/flake.nix @@ -7,7 +7,10 @@ { nixpkgs, ... }: let system = "x86_64-linux"; - pkgs = import nixpkgs { inherit system; }; + pkgs = import nixpkgs { + inherit system; + config.allowUnfreePredicate = pkg: builtins.elem (nixpkgs.lib.getName pkg) [ "terraform" ]; + }; in { devShells.${system}.default = pkgs.mkShell { diff --git a/templates/typescript/.envrc b/templates/typescript/.envrc deleted file mode 100644 index 3550a30..0000000 --- a/templates/typescript/.envrc +++ /dev/null @@ -1 +0,0 @@ -use flake diff --git a/templates/typescript/flake.nix b/templates/typescript/flake.nix deleted file mode 100644 index b4fe311..0000000 --- a/templates/typescript/flake.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ - description = "TypeScript (pnpm) development environment"; - - inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - - outputs = - { nixpkgs, ... }: - let - system = "x86_64-linux"; - pkgs = import nixpkgs { inherit system; }; - in - { - devShells.${system}.default = pkgs.mkShell { - buildInputs = [ - pkgs.nodejs_24 - pkgs.pnpm - pkgs.typescript - pkgs.typescript-language-server - pkgs.vscode-langservers-extracted - ]; - }; - }; -}