diff --git a/.envrc b/.envrc index 8fa7260429..7fcbc7c74b 100644 --- a/.envrc +++ b/.envrc @@ -9,29 +9,22 @@ store_paths=$(find . -name default.nix | grep -v '^./nix' | grep -v '^./dist-ne layout_dir=$(direnv_layout_dir) env_dir=./.env -# The env_dir used to be a symlink to env in nix store, if it exists, delete it. -[[ ! -L "$env_dir" ]] || rm -f "$env_dir" - [[ -d "$layout_dir" ]] || mkdir -p "$layout_dir" if [[ ! -d "$env_dir" || ! -f "$layout_dir/nix-rebuild" || "$store_paths" != $(< "$layout_dir/nix-rebuild" ) ]]; then - - [[ -d "$env_dir" ]] || mkdir -p "$env_dir" - - # this builds "wireServer.devShell" defined in ./nix/default.nix and outputs to ./.env - nix-shell ./nix -A wireServer.devShell --run 'direnv dump bash' > "${env_dir}/dev-shell.sh" - - nix-build ./nix -A profileEnv --out-link "${env_dir}/profile-env" + nix-build ./nix -A wireServer.devEnv --out-link ./.env echo "$store_paths" > "$layout_dir/nix-rebuild" fi -source_env "${env_dir}/dev-shell.sh" +PATH_add "./.env/bin" +path_add "PKG_CONFIG_PATH" "./.env/lib/pkgconfig" +path_add "LIBRARY_PATH" "./.env/lib" # source .profile from `$env`. This sets NIX_PATH to pkgs defined in # ./nix/default.nix. Tis is useful for nix tooling that runs inside this direnv, # e.g. "nix-shell -p foo" will get "foo" for pkgs defined in ./nix/default.nix -[[ -f "${env_dir}/profile-env/.profile" ]] && source_env "${env_dir}/profile-env/.profile" +[[ -f "./.env/.profile" ]] && source_env "./.env/.profile" # allow local .envrc overrides [[ -f .envrc.local ]] && source_env .envrc.local diff --git a/changelog.d/0-release-notes/nix-builds b/changelog.d/0-release-notes/nix-builds index 3dbdf2f44e..7bda5a83e0 100644 --- a/changelog.d/0-release-notes/nix-builds +++ b/changelog.d/0-release-notes/nix-builds @@ -1 +1 @@ -Build docker images using nix derivations instead of Dockerfiles (#2331, #2771, #2772, #2775) +Build docker images using nix derivations instead of Dockerfiles (#2331, #2771, #2772, #2775, #2776) diff --git a/nix/wire-server.nix b/nix/wire-server.nix index b197f4bf35..f07f1eada3 100644 --- a/nix/wire-server.nix +++ b/nix/wire-server.nix @@ -57,13 +57,13 @@ let lib = pkgs.lib; gitignoreSource = let gitignoreSrc = pkgs.fetchFromGitHub { - owner = "hercules-ci"; - repo = "gitignore.nix"; - # put the latest commit sha of gitignore Nix library here: - rev = "a20de23b925fd8264fd7fad6454652e142fd7f73"; - # use what nix suggests in the mismatch message here: - sha256 = "sha256:07vg2i9va38zbld9abs9lzqblz193vc5wvqd6h7amkmwf66ljcgh"; - }; + owner = "hercules-ci"; + repo = "gitignore.nix"; + # put the latest commit sha of gitignore Nix library here: + rev = "a20de23b925fd8264fd7fad6454652e142fd7f73"; + # use what nix suggests in the mismatch message here: + sha256 = "sha256:07vg2i9va38zbld9abs9lzqblz193vc5wvqd6h7amkmwf66ljcgh"; + }; in (import gitignoreSrc { inherit (pkgs) lib; }).gitignoreSource; # Mapping from package -> [executable] @@ -291,6 +291,21 @@ let lib = pkgs.lib; experimental-features = "nix-command"; }; }; + + shell = (hPkgs localModsOnlyTests).shellFor { + packages = p: builtins.map (e: p.${e}) wireServerPackages; + }; + ghcWithPackages = shell.nativeBuildInputs ++ shell.buildInputs; + + profileEnv = pkgs.writeTextFile { + name = "profile-env"; + destination = "/.profile"; + # This gets sourced by direnv. Set NIX_PATH, so `nix-shell` uses the same nixpkgs as here. + text = '' + export NIX_PATH=nixpkgs=${toString pkgs.path} + export LOCALE_ARCHIVE=${pkgs.glibcLocales}/lib/locale/locale-archive + ''; + }; in { inherit ciImage hoogleImage; @@ -303,11 +318,11 @@ in { enableTests = true; enableDocs = false; }; - imagesList = imagesList; + inherit imagesList; - devShell = (hPkgs localModsOnlyTests).shellFor { - packages = p: builtins.map (e: p.${e}) wireServerPackages; - buildInputs = commonTools ++ [ + devEnv = pkgs.buildEnv { + name = "wire-server-dev-env"; + paths = commonTools ++ [ (pkgs.haskell-language-server.override { supportedGhcVersions = [ "8107" ]; }) pkgs.ghcid pkgs.cfssl @@ -322,13 +337,16 @@ in { pkgs.cabal-install pkgs.haskellPackages.cabal-plan pkgs.nix-prefetch-git - ] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [ + profileEnv + ] + ++ ghcWithPackages + ++ pkgs.lib.optionals pkgs.stdenv.isLinux [ # linux-only, not strictly required tools - pkgs.docker-compose pkgs.telepresence ]; }; + inherit brig-templates; haskellPackages = hPkgs localModsEnableAll; haskellPackagesUnoptimizedNoDocs = hPkgs localModsOnlyTests;