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: flakes: allow overriding flake inputs in bulk with extra nix file #4193

Open
colemickens opened this issue Oct 27, 2020 · 7 comments
Open

Comments

@colemickens
Copy link
Member

colemickens commented Oct 27, 2020

Is your feature request related to a problem? Please describe.
Using --override-inputs forces an update to the lock file, which makes it harder for me to do "test with all of my own local overrides". (this is issue #3779)

Also, I have a few projects that are dependent on a number of other in-development flake repos. It's a bit much to have to carry around this list of flags:

function instantiate() {
  set -euo pipefail
  thing="${1:-".#hosts.$(hostname)"}"; [[ ! -z "${1:-}" ]] && shift
  out="$(set -euo pipefail; nix --experimental-features 'nix-command flakes' --pure-eval \
    eval \
      --override-input nixpkgs "/home/cole/code/nixpkgs/cmpkgs" \
      --override-input pipkgs "/home/cole/code/nixpkgs/pipkgs" \
      --override-input firefox "/home/cole/code/flake-firefox-nightly" \
      --override-input sops-nix "/home/cole/code/sops-nix" \
      --override-input home-manager "/home/cole/code/home-manager/cmhm" \
      --override-input nixpkgs-wayland "/home/cole/code/nixpkgs-wayland" \
      --override-input wip-pinebook-pro "/home/cole/code/wip-pinebook-pro" \
      --override-input nixos-veloren "/home/cole/code/nixos-veloren" \
      --override-input nixos-azure "/home/cole/code/nixos-azure" \
      --override-input mobile-nixos "/home/cole/code/mobile-nixos" \
      --raw "${thing}")"
  echo -e "${out}"
}

Describe the solution you'd like
Instead, maybe both of these problems could be addressed with the addition of an optional override file (conventionally named flake-overrides.nix, and normally assumed to be .gitignored.)

flake-overrides.nix:

{
  inputs.nixpkgs.url "/home/cole/code/nixpkgs/cmpkgs";
  inputs.pipkgs.url "/home/cole/code/nixpkgs/pipkgs";
  inputs.firefox.url = "/home/cole/code/flake-firefox-nightly";
  inputs.sops-nix.url = "/home/cole/code/sops-nix";
  inputs.home-manager.url = "/home/cole/code/home-manager/cmhm";
  inputs.nixpkgs-wayland.url = "/home/cole/code/nixpkgs-wayland";
  inputs.wip-pinebook-pro.url = "/home/cole/code/wip-pinebook-pro";
  inputs.nixos-veloren.url = "/home/cole/code/nixos-veloren";
  inputs.nixos-azure.url = "/home/cole/code/nixos-azure";
  inputs.mobile-nixos.url = "/home/cole/code/mobile-nixos";
}

used with: nix build --flake-overrides flake-overrides.nix '.#hosts.slynux'

Assumptions:

  • the format of the override file is the same as the schema for flake.nix, but only the inputs attribute is allowed
  • when using --flake-overrides, the flake.lock is not updated

Ideas:

  • maybe it could be --impure-overrides ./flake-overrides.nix
  • the build can/should be considered unreproducable (maybe --impure should be required)

Describe alternatives you've considered
n/a

Additional context
n/a

@B4dM4n
Copy link
Contributor

B4dM4n commented Nov 5, 2020

Some parts of this functionality are already available via the --inputs-from flag. It can provide the inputs of a second flake as registry entries for another flake:

primary/flake.nix:

{
  outputs = { nixpkgs }: { inherit (nixpkgs) legacyPackages; };
}

override/flake.nix:

{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/release-20.09";
  outputs = { ... }: { };
}
nix build --recreate-lock-file --no-write-lock-file --inputs-from override primary#hello

As far as I can tell, --inputs-from applies only to indirect registry inputs and not to other flake urls. For example the following flake input can not be overridden by it:
primary/flake.nix:

{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
  outputs = { nixpkgs }: { inherit (nixpkgs) legacyPackages; };
}

It would be useful if --inputs-from could be extended to override all inputs instead of only registry entries.

Adding a new flag is another option, but it might increase confusion over which of the many override flags should be used in which situation, as there already exist three of them:

--inputs-from FLAKE-URL                     use the inputs of the specified flake as registry entries
--override-flake ORIGINAL-REF RESOLVED-REF  override a flake registry value
--override-input INPUT-PATH FLAKE-URL       override a specific flake input (e.g. `dwarffs/nixpkgs`)

It would on the other hand complete the set of flags for overriding registry entries and flake inputs via other flakes and single arguments.

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/to-flake-or-not-to-flake/10047/4

@stale
Copy link

stale bot commented Jun 2, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Jun 2, 2021
@tpwrules
Copy link
Contributor

This would be useful to me as well.

@stale stale bot removed the stale label Jun 10, 2022
@colemickens
Copy link
Member Author

another option, make another flake: <root>/.nix/flakes/local/flake.nix

and do something like this:

{
  inputs = {
    "tow-boot-rpi" = { url = "path:/home/cole/code/tow-boot/rpi"; };
    "tow-boot-visionfive" = { url = "path:/home/cole/code/tow-boot/visionfive"; };

    "super" = {
      url = "path:../../";
      inputs."tow-boot-rpi".follows = "tow-boot-rpi";
      inputs."tow-boot-visionfive".follows = "tow-boot-visionfive";
    };
  };

  outputs = { ... }@inputs: inputs.super;
}

but then you still have to make sure to re-generate the lock file as needed, and it also winds up in some silly things happening - every single changes results in getting updated, and you have to re-create lock still, and it sort of duplicates all inputs that you are overriding.

@mikepurvis
Copy link

mikepurvis commented Jan 24, 2023

@colemickens Thanks for sharing this suggestion— I'm implementing something similar right now as an enabler for offline flake use, where super is the flake to be made offline-ready, and all URLs pointing to github and the like are instead overridden into path:/nix/store/ flakerefs containing the relevant flake sources.

One issue with it I've hit is that inputs only seems to be overrideable to a single level. So like, my wrapper flake can specify its super.url, and it can override the values of super.inputs.<foo>.url, but overriding super.inputs.<foo>.inputs.<bar>.url has no effect. This is with nix 2.9.0.

@msteen
Copy link

msteen commented Apr 24, 2023

I made a little tool to help me deal with this issue. I have only tested it with my use cases and for those it seems to work correctly. Guess I should share it in case it can help someone else out.

@colemickens It is very close to what you wished for, my approach just requires adding your target flake as part of the inputs and have it be the output. For example add inputs.output = "/path/to/your/."; and call it with my tool like nix-flake-override flake-overrides.nix 'inputs: inputs.output'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants