Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nix include git untracked files #406

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@
pkgs = import "${nixpkgs}" {
inherit system;
config.allowUnfree = true;
overlays = [
(final: prev: {
nix = prev.nix.overrideAttrs
(finalAttrs: prevAttrs: {
patches = (prevAttrs.patches or [ ]) ++ [
(final.fetchpatch {
name = "include-untracked-files.patch";
url = "https://github.com/NixOS/nix/compare/2.17.1...jfroche:nix:feat/include-untracked-files-2.17.1.patch";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have rebased the pull request in the Nix repository. Due to the recent changes in the main branch, specifically the transition to the libgit2 git implementation, the PR can no longer be directly applied with our current Nix version (2.17.1).
To address this, I've initiated a branch to backport the necessary changes for version 2.17.1.

excludes = [ "tests/functional/*" ];
hash = "sha256-HCGYzArlHO3Q0jIfc7rVD6AfV2wBzqY7VeU5DavexRE=";
})
];
requiredSystemFeatures = (prevAttrs.requiredSystemFeatures or [ ]) ++ [ "big-parallel" ];
});
})
];
};
strings = pkgs.lib.strings;
lists = pkgs.lib.lists;
Expand Down
3 changes: 2 additions & 1 deletion src/Garn/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ nixArgs :: [String]
nixArgs =
[ "--extra-experimental-features",
"flakes nix-command",
"--print-build-logs"
"--print-build-logs",
"--include-untracked-files"
]

currentSystem :: IO String
Expand Down
4 changes: 1 addition & 3 deletions src/Garn/GarnConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Garn.GarnConfig where

import Control.Exception (IOException, catch, throwIO)
import Control.Exception (throwIO)
import Control.Monad
import Cradle (Stderr (..), StdoutUntrimmed (..), run)
import Data.Aeson
Expand Down Expand Up @@ -189,8 +189,6 @@ writeGarnConfig :: GarnConfig -> IO ()
writeGarnConfig garnConfig = do
writeFile "flake.nix" $ flakeFile garnConfig
(StdoutUntrimmed _, Stderr _) <- run "nix" nixArgs "run" (nixpkgsInput <> "#nixpkgs-fmt") "./flake.nix"
void (run (words "git add --intent-to-add flake.nix") :: IO (StdoutUntrimmed, Stderr, ExitCode))
`catch` \(_ :: IOException) -> pure ()
pure ()

checkGarnFileExists :: IO ()
Expand Down
10 changes: 9 additions & 1 deletion test/spec/BuildSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module BuildSpec where

import Data.String.Interpolate (i)
import Data.String.Interpolate.Util (unindent)
import Development.Shake (StdoutTrim (..), cmd)
import Development.Shake (CmdOption (EchoStdout), StdoutTrim (..), cmd, cmd_)
import System.Directory
import System.Exit (ExitCode (..))
import Test.Hspec
Expand Down Expand Up @@ -190,3 +190,11 @@ spec = do
output <- runGarn ["build", "project"]
readFile "result/build-artifact" `shouldReturn` "hello from setup\n"
exitCode output `shouldBe` ExitSuccess

it "includes untracked files when building packages" $ \runGarn -> do
cmd_ "git init --initial-branch=main" (EchoStdout False)
writeHaskellProject repoDir
_ <- runGarn ["build", "foo"]
doesDirectoryExist "result" `shouldReturn` True
StdoutTrim output <- cmd ("result/bin/garn-test" :: String)
output `shouldBe` ("haskell test output" :: String)
20 changes: 0 additions & 20 deletions website/src/pages/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,26 +259,6 @@ export const deno = garn.mkProject({
.
</p>
</details>

<details>
<summary>
I'm getting no such file or directory errors for files that exist.
What's going on?
</summary>
<p>
<Garn /> uses nix under the hood which requires files in a git
repository to be tracked by git in order to see the files.
</p>
<p>
To resolve this make sure to either add untracked files to git (e.g.
with <code>git add $YOUR_FILES</code>), or mark them as intended
additions with <code>git add --intent-to-add $YOUR_FILES</code>
</p>
<p>
Likely this requirement will be removed from future <Garn />{" "}
versions.
</p>
</details>
</section>
</>
);
Expand Down