nix-community / impermanence

Modules to help you handle persistent state on systems with ephemeral root storage [maintainer=@talyz]
MIT License
1.1k stars 81 forks source link

nixos: Fix "Argument list too long" error #23

Closed linyinfeng closed 3 years ago

linyinfeng commented 3 years ago

I encountered a weird "Argument list too long" error when building system configuration.

# nixos-rebuild --flake /etc/nixos build -vvvv --show-trace
...
... long regular outputs ...
...
building '/nix/store/pgnfd73mkzyzzz613lahx94hgpsri557-nixos-system-yinfeng-work-21.03.20201109.b839d4a.drv'...
building of '/nix/store/pgnfd73mkzyzzz613lahx94hgpsri557-nixos-system-yinfeng-work-21.03.20201109.b839d4a.drv!out' from .drv file: got EOF
building of '/nix/store/pgnfd73mkzyzzz613lahx94hgpsri557-nixos-system-yinfeng-work-21.03.20201109.b839d4a.drv!out' from .drv file: woken up
building of '/nix/store/pgnfd73mkzyzzz613lahx94hgpsri557-nixos-system-yinfeng-work-21.03.20201109.b839d4a.drv!out' from .drv file: build done
killing process 2625
builder process for '/nix/store/pgnfd73mkzyzzz613lahx94hgpsri557-nixos-system-yinfeng-work-21.03.20201109.b839d4a.drv' finished
killing all processes running under uid '30001'
lock released on '/nix/store/6yf0nssx29rssphzr1ns94pglxgy2ik3-nixos-system-yinfeng-work-21.03.20201109.b839d4a.lock'
building of '/nix/store/pgnfd73mkzyzzz613lahx94hgpsri557-nixos-system-yinfeng-work-21.03.20201109.b839d4a.drv!out' from .drv file: done
building of '/nix/store/pgnfd73mkzyzzz613lahx94hgpsri557-nixos-system-yinfeng-work-21.03.20201109.b839d4a.drv!out' from .drv file: goal destroyed
error: --- Error -------------------------------------------------------------------------------------------------------------------------------------------------------------- nix
builder for '/nix/store/pgnfd73mkzyzzz613lahx94hgpsri557-nixos-system-yinfeng-work-21.03.20201109.b839d4a.drv' failed with exit code 1; last 2 log lines:

  ErroSysError{executing '/nix/store/qdp56fi357fgxxnkjrwx1g67hrk775im-bash-4.4-p23/bin/bash': Argument list too long

Because the configuration have over 50 directories in environment.persistence."/persist".directories...

Seems the issue was caused by a too long activation script. It can be easily fixed by writing the generated script into nix store. This fix is borrowed from NixOS/nixops/pull/915.

linyinfeng commented 3 years ago

@talyz Thank you for your suggestion. I have added two commits for this PR. Now the script part will be written into store and the activation script should looks like this (test on my machine):

$ cat /run/current-system/activate
...
#### Activation script snippet createDirsIn--persist:
_localstatus=0
/nix/store/6a28cn56k9i8cfazs9bd4f45gchgv4fq-impermanence-create-directories "/persist" "/etc/nixos"
/nix/store/6a28cn56k9i8cfazs9bd4f45gchgv4fq-impermanence-create-directories "/persist" "/etc/NetworkManager/system-connections"
/nix/store/6a28cn56k9i8cfazs9bd4f45gchgv4fq-impermanence-create-directories "/persist" "/var/log"
/nix/store/6a28cn56k9i8cfazs9bd4f45gchgv4fq-impermanence-create-directories "/persist" "/var/lib/docker"
/nix/store/6a28cn56k9i8cfazs9bd4f45gchgv4fq-impermanence-create-directories "/persist" "/var/lib/flatpak"
/nix/store/6a28cn56k9i8cfazs9bd4f45gchgv4fq-impermanence-create-directories "/persist" "/var/lib/bluetooth"
/nix/store/6a28cn56k9i8cfazs9bd4f45gchgv4fq-impermanence-create-directories "/persist" "/var/lib/libvirt"
/nix/store/6a28cn56k9i8cfazs9bd4f45gchgv4fq-impermanence-create-directories "/persist" "/var/lib/systemd/coredump"
...

BTW, actually the old fix only create 1 file per persistence storage location per generation, but the file will have over 50 identical sections of codes.

Also, this TODO,

# TODO: Move this script to it's own file, add CI with shfmt/shellcheck.

can be performed easily if this PR is merged.

Finally, CI of this repository is broken now...

> Run cachix/install-nix-action@v9
...
Error: Unable to process command '::add-path::/nix/var/nix/profiles/per-user/runner/profile/bin' successfully.
Error: The `add-path` command is disabled. Please upgrade to using Environment Files or opt into unsecure command execution by setting the `ACTIONS_ALLOW_UNSECURE_COMMANDS` environment variable to `true`. For more information see: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/
...
lovesegfault commented 3 years ago

Please rebase to pick up the CI fixes :)

talyz commented 3 years ago

Thanks!