MatthewCroughan / nixinate

Another NixOS Deployment Tool - Nixinate your systems 🕶️
MIT License
240 stars 32 forks source link

Carry over --impure from initial nix run to nixinate evaluation #54

Open rschardt opened 3 months ago

rschardt commented 3 months ago

I have some scripts which require --impure mode to be enabled.

        {
          _module.args.nixinate = {
            host = "host";
            sshUser = "root";
            buildOn = "local";
            substituteOnTarget = false;
            hermetic = false;
            nixOptions = [ "--impure" ];
          };
        }
  1. Option: I would expect that 'nix run .#apps.nixinate.machine' now runs as impure without using the --impure option explicitly :

    error:
       … in the left operand of the update (//) operator
    
         at /nix/store/7gzgi8zsnh06pv9cphb30yv9h1pyn4nk-source/flake.nix:84:20:
    
           83|                    )
           84|                    // nixpkgs.lib.genAttrs
             |                    ^
           85|                       (map (a: a + "-dry-run") validMachines)
    
       … while calling the 'listToAttrs' builtin
    
         at /nix/store/f0ddmw6s86y567yg06h5019z72szbzch-source/lib/attrsets.nix:1248:5:
    
         1247|     f:
         1248|     listToAttrs (map (n: nameValuePair n (f n)) names);
             |     ^
         1249|
    
       (stack trace truncated; use '--show-trace' to show the full trace)
    
       error: access to absolute path '/etc/hostname' is forbidden in pure eval mode (use '--impure' to override)

My script tries to read /etc/hostname therefore we ran into problems here.

  1. Option: However if we decide to run 'nix run .#apps.nixinate.machine --impure' we bypass the error.
  2. Option: Just running 'nix run .#apps.nixinate.machine --impure' without settings the nixOption still fails with the pure eval mode error.

So I guess arguments passed to nix run don't really carry over when nixosConfigurations are evaluated/built atleast. Maybe there is a way to read arguments passed to nix run during evaluation and concat them with the maybe provided nixOptions options?