thoughtpolice / buck2-nix

Do not taunt happy fun ball
59 stars 4 forks source link

Fully automated setup command doesn't work. #8

Closed Fuuzetsu closed 1 year ago

Fuuzetsu commented 1 year ago
[shana@aya:~/programming]$ cd buck2-nix-experiment/

[shana@aya:~/programming/buck2-nix-experiment]$ nix run \
    --tarball-ttl 0 \
    --accept-flake-config \
    'github:thoughtpolice/buck2-nix?dir=buck/nix#setup'
error:
       … while evaluating the attribute 'packages'

         at /nix/store/hafdh6gwaaw32zfgkckdny4rdkcicxvy-source/buck/nix/flake.nix:162:9:

          161|         inherit (jobs) devShells;
          162|         packages = rec {
             |         ^
          163|           # By default, build all the packages in the tree when just running

       … in the right operand of the update (//) operator

         at /nix/store/hafdh6gwaaw32zfgkckdny4rdkcicxvy-source/buck/nix/flake.nix:182:11:

          181|           # toolchains, et cetera.
          182|         } // flatJobs;
             |           ^
          183|

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: getting status of '/nix/store/hafdh6gwaaw32zfgkckdny4rdkcicxvy-source/buck/nix/toolchains': No such file or directory

[shana@aya:~/programming/buck2-nix-experiment]$ nix --version
nix (Nix) 2.14.1

[shana@aya:~/programming/buck2-nix-experiment]$ nix run     --tarball-ttl 0     --accept-flake-config     'github:thoughtpolice/buck2-nix?dir=buck/nix#setup' --show-trace
error:
       … while evaluating the attribute 'packages'

         at /nix/store/hafdh6gwaaw32zfgkckdny4rdkcicxvy-source/buck/nix/flake.nix:162:9:

          161|         inherit (jobs) devShells;
          162|         packages = rec {
             |         ^
          163|           # By default, build all the packages in the tree when just running

       … in the right operand of the update (//) operator

         at /nix/store/hafdh6gwaaw32zfgkckdny4rdkcicxvy-source/buck/nix/flake.nix:182:11:

          181|           # toolchains, et cetera.
          182|         } // flatJobs;
             |           ^
          183|

       … from call site

         at /nix/store/hafdh6gwaaw32zfgkckdny4rdkcicxvy-source/buck/nix/flake.nix:155:20:

          154|         # Flatten the hierarchy; mostly used to ensure we build everything...
          155|         flatJobs = flake-utils.lib.flattenTree rec {
             |                    ^
          156|           packages = jobs.packages // { recurseForDerivations = true; };

       … while calling 'flattenTree'

         at /nix/store/fy3x5qk811q1kjilcv1416p311pfh1a5-source/default.nix:171:17:

          170|   #   }
          171|   flattenTree = tree: import ./flattenTree.nix tree;
             |                 ^
          172|

       … from call site

         at /nix/store/fy3x5qk811q1kjilcv1416p311pfh1a5-source/default.nix:171:23:

          170|   #   }
          171|   flattenTree = tree: import ./flattenTree.nix tree;
             |                       ^
          172|

       … while calling anonymous lambda

         at /nix/store/fy3x5qk811q1kjilcv1416p311pfh1a5-source/flattenTree.nix:1:1:

            1| tree:
             | ^
            2| let

       … from call site

         at /nix/store/fy3x5qk811q1kjilcv1416p311pfh1a5-source/flattenTree.nix:35:1:

           34| in
           35| recurse { } [ ] tree
             | ^
           36|

       … while calling 'recurse'

         at /nix/store/fy3x5qk811q1kjilcv1416p311pfh1a5-source/flattenTree.nix:28:24:

           27|
           28|   recurse = sum: path: val:
             |                        ^
           29|     builtins.foldl'

       … while calling anonymous lambda

         at /nix/store/fy3x5qk811q1kjilcv1416p311pfh1a5-source/flattenTree.nix:30:13:

           29|     builtins.foldl'
           30|       (sum: key: op sum (path ++ [ key ]) val.${key})
             |             ^
           31|       sum

       … from call site

         at /nix/store/fy3x5qk811q1kjilcv1416p311pfh1a5-source/flattenTree.nix:30:18:

           29|     builtins.foldl'
           30|       (sum: key: op sum (path ++ [ key ]) val.${key})
             |                  ^
           31|       sum

       … while calling 'op'

         at /nix/store/fy3x5qk811q1kjilcv1416p311pfh1a5-source/flattenTree.nix:3:19:

            2| let
            3|   op = sum: path: val:
             |                   ^
            4|     let

       error: getting status of '/nix/store/hafdh6gwaaw32zfgkckdny4rdkcicxvy-source/buck/nix/toolchains': No such file or directory
thoughtpolice commented 1 year ago

Oh, interesting, I seem to have broke something. I'll look into it when I get a chance later today.

thoughtpolice commented 1 year ago

@Fuuzetsu This should be fixed now I think with d3caf5249de25ba3445ee10b372c51a984e5ee91, please give it a try. The installer still seems to work for me.

Also you don't have to nix run the given command from any directory; it's intended to run from like, $HOME or something. It doesn't put anything in $PWD on its own, and it will check out the source code for you automatically using Sapling, Jujutsu, or Git, to a directory of your choosing (defaulting to approximately $HOME/buck2-nix)

thoughtpolice commented 1 year ago

Here's a full run of the installer from my WSL workstation, which should give you an idea of what you'll see (note: you'll actually get terminal UI prompts to answer)

austin@GANON:~$ nix run     --tarball-ttl 0     --accept-flake-config     'github:thoughtpolice/buck2-nix?dir=buck/nix#setup'
? 👋  Welcome to the setup installer for the project and build system.

    This installer tool largely automates installation of 'direnv' as well as
    using your chosen source code management tool to clone the repository, and
    warning the user of some gotchas.

    This is a work in progress, and may have bugs.

    You can quit at any time with Ctrl-C

🛫  Performing pre-flight setup checks...

⠏ [1/4] Checking the operating system... OK!
⠋ [2/4] Checking installed Nix version... OK!
⠙ [3/4] Checking if direnv is installed... OK!
⠹ [4/4] Checking for your $USER in Nix 'trusted-users'... OK!

🎉  Setup complete!

✔ Which source code management tool do you want to use? · ❓ What's the difference?

  The following tools can be used to clone the source code and manage
  the repository. Each has their own advantages and disadvantages.

  NOTE: The following tools are all compatible with the upstream Git
        repository.

  🍃 Sapling is designed for stacked patch workflows, and ease of use.

         Homepage: <https://sapling-scm.com>

     It is Git-compatible, and designed for a stacked patch workflow; it features
     no staging area, a first-class web UI, aggressive support for rebasing, and a
     and easy to use terminal UI for novices or experienced users.

     Sapling is the recommended VCS for contributing.

  🥋 Jujutsu is designed to augment the Git data model with new features.

         Homepage: <https://github.com/martinvonz/jj>

     It combines features like Mercurial revsets, powerful undo and history
     rewriting, first-class conflicts, and no staging area (known as
     "working-copy-as-a-commit")

     Jujutsu is experimental, but can be used to contribute.

  👴 Git is The Stupid Content Tracker; the classic VCS we know and love.

         Homepage: <https://git-scm.com>

     Git is the most popular VCS in the world, and is used by many projects.
     But it is not recommended for contributing, unless you are an experienced
     Git user and know how to use it with stacked patches and rebase-heavy
     workflows.

✔ Which source code management tool do you want to use? · 1️⃣  🍃 Sapling (Recommended)
✔ What directory would you like to clone the repository into? · /home/austin
✔ What name would you like to use for the cloned checkout? · buck2-nix.sl
? I'm going to:

    Clone the repository https://github.com/thoughtpolice/buck2-nix
     into the directory  /home/austin/buck2-nix.sl
        using 🍃 Sapling

2023-04-12T14:21:02.917074Z  INFO these 2 paths will be fetched (34.31 MiB download, 170.15 MiB unpacked):
2023-04-12T14:21:02.917106Z  INFO   /nix/store/8fw4fh5nsypnxj9j92nay6xwv8q7nnhg-python3.8-sapling-main-0.1.20221118-210929-cfbb68aa
2023-04-12T14:21:02.917111Z  INFO   /nix/store/k0xws6hy9mvlqqip5bi5cshqs2bh6sbj-sapling-0.1.20221118-210929-cfbb68aa
2023-04-12T14:21:02.918867Z  INFO copying path '/nix/store/8fw4fh5nsypnxj9j92nay6xwv8q7nnhg-python3.8-sapling-main-0.1.20221118-210929-cfbb68aa' from 'https://cache.nixos.org'...
2023-04-12T14:21:06.050564Z  INFO copying path '/nix/store/k0xws6hy9mvlqqip5bi5cshqs2bh6sbj-sapling-0.1.20221118-210929-cfbb68aa' from 'https://cache.nixos.org'...
2023-04-12T14:21:08.558851Z  INFO From https://github.com/thoughtpolice/buck2-nix
2023-04-12T14:21:08.558879Z  INFO  * [new ref]         d3caf5249de25ba3445ee10b372c51a984e5ee91 -> remote/main
marked 0 commits as landed
91 files updated, 0 files merged, 0 files removed, 0 files unresolved
Successfully cloned https://github.com/thoughtpolice/buck2-nix into /home/austin/buck2-nix.sl

✔ May I 'direnv allow' the .envrc file located in '/home/austin/buck2-nix.sl'? · yes
? Would you like to enable 👀 Watchman for file tracking?

    Watchman is an efficient daemon for tracking many file changes across a
    large number of directories. The build system, Buck, can integrate directly
    with Watchman to more efficiently track all file changes.

    If you answer 'y' here, then Watchman will be enabled on-demand by creating
    a transient systemd service. It is never installed permanently, and you can
    remove this service at any time and it is not persistent. This is done by
    creating a file named '.use_watchman' at the root of the repository.

    You can undo any choice you make at any time.

  👀 Watchman enabled!

✔ Finished! 🎉 🎉 🎉

  You can now 'cd' into '/home/austin/buck2-nix.sl' and begin developing!

  Upon doing so, direnv will activate, populating your shell with the needed environment.
Fuuzetsu commented 1 year ago

I got very slightly further but not by much:

[shana@aya:~/programming/buck2-nix-experiment]$ nix -L run     --tarball-ttl 0     --accept-flake-config     'github:thoughtpolice/buck2-nix?dir=buck/nix#setup'
setup> unpacking sources
setup> unpacking source archive /nix/store/pfbql2fklkygxliwq3dld7bvlwcwrw4j-source/buck/nix
setup> source root is nix
setup> Executing cargoSetupPostUnpackHook
setup> Finished cargoSetupPostUnpackHook
setup> patching sources
setup> /nix/store/sw36plhp82916wwg6i6097rkzza7d950-stdenv-linux/setup: line 119: cd: buck/nix/setup: No such file or directory
setup> /nix/store/sw36plhp82916wwg6i6097rkzza7d950-stdenv-linux/setup: line 136: pop_var_context: head of shell_variables not a function context
error: builder for '/nix/store/6ix45pdbaq5plg9jh0ihgw3i1dp1p2x4-setup.drv' failed with exit code 1;
       last 8 log lines:
       > unpacking sources
       > unpacking source archive /nix/store/pfbql2fklkygxliwq3dld7bvlwcwrw4j-source/buck/nix
       > source root is nix
       > Executing cargoSetupPostUnpackHook
       > Finished cargoSetupPostUnpackHook
       > patching sources
       > /nix/store/sw36plhp82916wwg6i6097rkzza7d950-stdenv-linux/setup: line 119: cd: buck/nix/setup: No such file or directory
       > /nix/store/sw36plhp82916wwg6i6097rkzza7d950-stdenv-linux/setup: line 136: pop_var_context: head of shell_variables not a function context
       For full logs, run 'nix log /nix/store/6ix45pdbaq5plg9jh0ihgw3i1dp1p2x4-setup.drv'.
thoughtpolice commented 1 year ago

Hmmm, out of curiosity, what version of Nix are you using? I wonder if this is something that broke in a forward/backward incompatible way...

Fuuzetsu commented 1 year ago

Hmmm, out of curiosity, what version of Nix are you using? I wonder if this is something that broke in a forward/backward incompatible way...

2.14.1, it was in OP, somewhat hidden

thoughtpolice commented 1 year ago

Probably something to do with this:

https://github.com/thoughtpolice/buck2-nix/blob/22f9052adf8991e895e167cd103ea3543168f04d/buck/nix/flake.nix#L80-L89

I'll have to upgrade Nix and take a closer look soon...

thoughtpolice commented 1 year ago

I reproduced this issue; it was a change in Nix 2.14 that I hadn't seen until now; please see f3f0ab5b. And after spending some time whacking at the CI and nix run invocation (it's just easiest to test it after committing, so I had a few false starts...) it seems to be working again. The same nix run invocation should work fine, now.

The CI has been migrated and minimum supported Nix version bumped to 2.14 as well. Let me know if it still freaks out on you!

thoughtpolice commented 1 year ago

Also: I'll note that when you have to pick a VCS, Sapling is the only really supported tool at the moment, though Jujutsu should still work too, I think. The choice between them is another experiment I'm doing on my own (I like them both), so don't let it distract you if you don't care. Sapling is very good.

Fuuzetsu commented 1 year ago

Thanks. It got further now, it now crashes at runtime, during the setup. Let me know if I should open a separate issue.

? 👋  Welcome to the setup installer for the project and build system.

    This installer tool largely automates installation of 'direnv' as well as
    using your chosen source code management tool to clone the repository, and
    warning the user of some gotchas.

    This is a work in progress, and may have bugs.

    You can quit at any time with Ctrl-C

🛫  Performing pre-flight setup checks...

⠏ [1/4] Checking the operating system... OK!                                                                                                                                                                                                                                     
⠋ [2/4] Checking installed Nix version... OK!                                                                                                                                                                                                                                    
⠙ [3/4] Checking if direnv is installed... OK!                                                                                                                                                                                                                                   
Error: 
   0: direnv not installed

Location:
   src/main.rs:250

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SPANTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   0: setup::check_direnv
      at src/main.rs:233

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

[shana@aya:~/programming/buck2-nix-experiment]$ which direnv
/run/current-system/sw/bin/direnv

I've installed direnv by putting it in my NixOS package list, but I never ran it. Maybe I have to set something extra up, unsure.

Fuuzetsu commented 1 year ago

I've installed direnv by putting it in my NixOS package list, but I never ran it. Maybe I have to set something extra up, unsure.

Turns out I just had to follow https://direnv.net/docs/hook.html

Fuuzetsu commented 1 year ago

I've installed direnv by putting it in my NixOS package list, but I never ran it. Maybe I have to set something extra up, unsure.

Turns out I just had to follow https://direnv.net/docs/hook.html

Hm, actually that didn't work. I'll try to set it up in whatever way needed and try it later. Sorry for the noise.

[shana@aya:~/programming/buck2-nix-experiment]$ bash --login -c "type -t _direnv_hook"

[shana@aya:~/programming/buck2-nix-experiment]$ type -t _direnv_hook
function

EDIT: It turns out it works if I put the line from the setup page into ~/.bash_profile instead. Seems ~/.bashrc isn't sourced in non-interactive shells, at least on my NixOS setup.

thoughtpolice commented 1 year ago

Yeah, this was something I remember running into and sort of scratching my head on how to give an informative error. Thanks for hitting it with a hammer and trying it out anyway!