From 238fb08a68b5541ea1b972222b7fc4227030f52a Mon Sep 17 00:00:00 2001 From: Marcus Ramberg Date: Wed, 5 Feb 2025 08:32:45 +0100 Subject: [PATCH] feat: setup devenv shell --- .envrc | 12 +-- .gitignore | 1 + flake.lock | 221 ++++++++++++++++++++++++++++++++++++++++++++++++++++- flake.nix | 44 +++++++++-- shell.nix | 26 ------- 5 files changed, 258 insertions(+), 46 deletions(-) delete mode 100644 shell.nix diff --git a/.envrc b/.envrc index 46f1751..7d3016f 100644 --- a/.envrc +++ b/.envrc @@ -1,11 +1 @@ -if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then - source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs=" -fi - -watch_file devenv.nix -watch_file devenv.lock -watch_file devenv.yaml -if ! use flake . --impure -then - echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2 -fi + use flake . --no-pure-eval diff --git a/.gitignore b/.gitignore index aad6e25..3237549 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ helmfile-nix result .direnv +.devenv diff --git a/flake.lock b/flake.lock index 59268d1..ffc2d27 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,95 @@ { "nodes": { + "cachix": { + "inputs": { + "devenv": [ + "devenv" + ], + "flake-compat": [ + "devenv" + ], + "git-hooks": [ + "devenv" + ], + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1728672398, + "narHash": "sha256-KxuGSoVUFnQLB2ZcYODW7AVPAh9JqRlD5BrfsC/Q4qs=", + "owner": "cachix", + "repo": "cachix", + "rev": "aac51f698309fd0f381149214b7eee213c66ef0a", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "latest", + "repo": "cachix", + "type": "github" + } + }, + "devenv": { + "inputs": { + "cachix": "cachix", + "flake-compat": "flake-compat", + "git-hooks": "git-hooks", + "nix": "nix", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1738414267, + "narHash": "sha256-7B+rkQlQ8zIzVgJRiu49ZFST6NBWt+JsnQZ/Q4W3qlI=", + "owner": "cachix", + "repo": "devenv", + "rev": "3f49b4afbb9a80b1e81fb6071f59dac152177efa", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "devenv", + "nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1712014858, + "narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9126214d0a59633752a136528f5f3b9aa8565b7d", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -18,6 +108,53 @@ "type": "github" } }, + "git-hooks": { + "inputs": { + "flake-compat": [ + "devenv" + ], + "gitignore": "gitignore", + "nixpkgs": [ + "devenv", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1737301351, + "narHash": "sha256-2UNmLCKORvdBRhPGI8Vx0b6l7M8/QBey/nHLIxOl4jE=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "15a87cedeb67e3dbc8d2f7b9831990dffcf4e69f", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "devenv", + "git-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "gomod2nix": { "inputs": { "flake-utils": [ @@ -41,7 +178,88 @@ "type": "github" } }, + "libgit2": { + "flake": false, + "locked": { + "lastModified": 1697646580, + "narHash": "sha256-oX4Z3S9WtJlwvj0uH9HlYcWv+x1hqp8mhXl7HsLu2f0=", + "owner": "libgit2", + "repo": "libgit2", + "rev": "45fd9ed7ae1a9b74b957ef4f337bc3c8b3df01b5", + "type": "github" + }, + "original": { + "owner": "libgit2", + "repo": "libgit2", + "type": "github" + } + }, + "nix": { + "inputs": { + "flake-compat": [ + "devenv" + ], + "flake-parts": "flake-parts", + "libgit2": "libgit2", + "nixpkgs": "nixpkgs_2", + "nixpkgs-23-11": [ + "devenv" + ], + "nixpkgs-regression": [ + "devenv" + ], + "pre-commit-hooks": [ + "devenv" + ] + }, + "locked": { + "lastModified": 1734114420, + "narHash": "sha256-n52PUzub5jZWc8nI/sR7UICOheU8rNA+YZ73YaHeCBg=", + "owner": "domenkozar", + "repo": "nix", + "rev": "bde6a1a0d1f2af86caa4d20d23eca019f3d57eee", + "type": "github" + }, + "original": { + "owner": "domenkozar", + "ref": "devenv-2.24", + "repo": "nix", + "type": "github" + } + }, "nixpkgs": { + "locked": { + "lastModified": 1730531603, + "narHash": "sha256-Dqg6si5CqIzm87sp57j5nTaeBbWhHFaVyG7V6L8k3lY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7ffd9ae656aec493492b44d0ddfb28e79a1ea25d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1717432640, + "narHash": "sha256-+f9c4/ZX5MWDOuB1rKoWj+lBNm0z0rs4CK47HBLxy1o=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "88269ab3044128b7c2f4c7d68448b2fb50456870", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "release-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { "locked": { "lastModified": 1712963716, "narHash": "sha256-WKm9CvgCldeIVvRz87iOMi8CFVB1apJlkUT4GGvA0iM=", @@ -59,9 +277,10 @@ }, "root": { "inputs": { + "devenv": "devenv", "flake-utils": "flake-utils", "gomod2nix": "gomod2nix", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs_3" } }, "systems": { diff --git a/flake.nix b/flake.nix index 9b6604c..49be800 100644 --- a/flake.nix +++ b/flake.nix @@ -1,27 +1,55 @@ { description = "helmfile-nix"; + inputs.devenv.url = "github:cachix/devenv"; + inputs.devenv.inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; inputs.flake-utils.url = "github:numtide/flake-utils"; inputs.gomod2nix.url = "github:nix-community/gomod2nix"; inputs.gomod2nix.inputs.nixpkgs.follows = "nixpkgs"; inputs.gomod2nix.inputs.flake-utils.follows = "flake-utils"; - outputs = { self, nixpkgs, flake-utils, gomod2nix }: - (flake-utils.lib.eachDefaultSystem (system: + outputs = + { + devenv, + flake-utils, + gomod2nix, + nixpkgs, + self, + }@inputs: + (flake-utils.lib.eachDefaultSystem ( + system: let pkgs = nixpkgs.legacyPackages.${system}; # The current default sdk for macOS fails to compile go projects, so we use a newer one for now. # This has no effect on other platforms. - callPackage = - pkgs.darwin.apple_sdk_11_0.callPackage or pkgs.callPackage; - in { + callPackage = pkgs.darwin.apple_sdk_11_0.callPackage or pkgs.callPackage; + in + { packages.default = callPackage ./. { inherit (gomod2nix.legacyPackages.${system}) buildGoApplication; }; - devShells.default = callPackage ./shell.nix { - inherit (gomod2nix.legacyPackages.${system}) mkGoEnv gomod2nix; + devShells.default = devenv.lib.mkShell { + inherit inputs pkgs; + modules = [ + ( + { pkgs, ... }: + let + goEnv = gomod2nix.legacyPackages.${system}.mkGoEnv { pwd = ./.; }; + in + { + packages = with pkgs; [ + goEnv + gomod2nix.legacyPackages.${system}.gomod2nix + docker + helmfile + kubernetes-helm + ]; + } + ) + ]; }; - })); + } + )); } diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 53e25dc..0000000 --- a/shell.nix +++ /dev/null @@ -1,26 +0,0 @@ -{ - pkgs ? ( - let - inherit (builtins) fetchTree fromJSON readFile; - inherit ((fromJSON (readFile ./flake.lock)).nodes) nixpkgs gomod2nix; - in - import (fetchTree nixpkgs.locked) { - overlays = [ (import "${fetchTree gomod2nix.locked}/overlay.nix") ]; - } - ), - mkGoEnv ? pkgs.mkGoEnv, - gomod2nix ? pkgs.gomod2nix, -}: - -let - goEnv = mkGoEnv { pwd = ./.; }; -in -pkgs.mkShell { - packages = [ - goEnv - gomod2nix - pkgs.docker - pkgs.helmfile - pkgs.kubernetes-helm - ]; -}