From e6a9e578b44c2a83af3a710b85cc3b92a6deff8c Mon Sep 17 00:00:00 2001 From: Peter Kolloch Date: Mon, 23 Oct 2023 11:53:03 +0200 Subject: [PATCH] fix: quoting of PRJ_PATH/fragment for installables https://github.com/divnix/std/issues/357 --- src/local/flake.lock | 29 ++++++---------------- src/std/fwlib/blockTypes/installables.nix | 24 ++++++++++++------ src/std/templates/rust/nix/repo/shells.nix | 4 +-- src/tests/flake.lock | 29 ++++++---------------- 4 files changed, 35 insertions(+), 51 deletions(-) diff --git a/src/local/flake.lock b/src/local/flake.lock index 1813cd88..5d0214c3 100644 --- a/src/local/flake.lock +++ b/src/local/flake.lock @@ -113,7 +113,10 @@ }, "haumea": { "inputs": { - "nixpkgs": "nixpkgs_2" + "nixpkgs": [ + "std", + "lib" + ] }, "locked": { "lastModified": 1685133229, @@ -250,21 +253,6 @@ "type": "github" } }, - "nixpkgs_2": { - "locked": { - "lastModified": 1681001314, - "narHash": "sha256-5sDnCLdrKZqxLPK4KA8+f4A3YKO/u6ElpMILvX0g72c=", - "owner": "nix-community", - "repo": "nixpkgs.lib", - "rev": "367c0e1086a4eb4502b24d872cea2c7acdd557f4", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "nixpkgs.lib", - "type": "github" - } - }, "nosys": { "locked": { "lastModified": 1668010795, @@ -375,12 +363,12 @@ }, "locked": { "lastModified": 0, - "narHash": "sha256-2nEaxNN7Kn7+keuE1uTh12RiiLJ/5AgGz6vkTW1rH40=", - "path": "/nix/store/ziag42cacmzalvibkjy7vbl9z76kjlqf-source", + "narHash": "sha256-3jw+c8xu0ia5ZD7QaZGqWKdUXRJ5fDZrYUpiKdPEOzs=", + "path": "/nix/store/kabv0zhhn0b00fvw4xrr9i1q7g8bz298-source", "type": "path" }, "original": { - "path": "/nix/store/ziag42cacmzalvibkjy7vbl9z76kjlqf-source", + "path": "/nix/store/kabv0zhhn0b00fvw4xrr9i1q7g8bz298-source", "type": "path" } }, @@ -403,8 +391,7 @@ "inputs": { "nixpkgs": [ "std", - "haumea", - "nixpkgs" + "lib" ] }, "locked": { diff --git a/src/std/fwlib/blockTypes/installables.nix b/src/std/fwlib/blockTypes/installables.nix index 5ef509c2..8efc5c5e 100644 --- a/src/std/fwlib/blockTypes/installables.nix +++ b/src/std/fwlib/blockTypes/installables.nix @@ -1,6 +1,7 @@ { root, super, + nixpkgs, }: /* Use the Installables Blocktype for targets that you want to @@ -18,6 +19,7 @@ Available actions: let inherit (root) mkCommand actions; inherit (super) addSelectorFunctor; + l = nixpkgs.lib // builtins; in name: { __functor = addSelectorFunctor; @@ -29,33 +31,41 @@ in fragmentRelPath, target, inputs, - }: [ + }: let + escapedFragment = l.escapeShellArg fragment; + in [ (actions.build currentSystem target) # profile commands require a flake ref (mkCommand currentSystem "install" "install this target" [] '' # ${target} - nix profile install $PRJ_ROOT#${fragment} + set -x + nix profile install "$PRJ_ROOT#"${escapedFragment} '' {}) (mkCommand currentSystem "upgrade" "upgrade this target" [] '' # ${target} - nix profile upgrade $PRJ_ROOT#${fragment} + set -x + nix profile upgrade "$PRJ_ROOT#"${escapedFragment} '' {}) (mkCommand currentSystem "remove" "remove this target" [] '' # ${target} - nix profile remove $PRJ_ROOT#${fragment} + set -x + nix profile remove "$PRJ_ROOT#"${escapedFragment} '' {}) # TODO: use target. `nix bundle` requires a flake ref, but we may be able to use nix-bundle instead as a workaround (mkCommand currentSystem "bundle" "bundle this target" [] '' # ${target} - nix bundle --bundler github:Ninlives/relocatable.nix --refresh $PRJ_ROOT#${fragment} + set -x + nix bundle --bundler github:Ninlives/relocatable.nix --refresh "$PRJ_ROOT#"${escapedFragment} '' {}) (mkCommand currentSystem "bundleImage" "bundle this target to image" [] '' # ${target} - nix bundle --bundler github:NixOS/bundlers#toDockerImage --refresh $PRJ_ROOT#${fragment} + set -x + nix bundle --bundler github:NixOS/bundlers#toDockerImage --refresh "$PRJ_ROOT#"${escapedFragment} '' {}) (mkCommand currentSystem "bundleAppImage" "bundle this target to AppImage" [] '' # ${target} - nix bundle --bundler github:ralismark/nix-appimage --refresh $PRJ_ROOT#${fragment} + set -x + nix bundle --bundler github:ralismark/nix-appimage --refresh "$PRJ_ROOT#"${escapedFragment} '' {}) ]; } diff --git a/src/std/templates/rust/nix/repo/shells.nix b/src/std/templates/rust/nix/repo/shells.nix index e923698c..40c3cfa2 100644 --- a/src/std/templates/rust/nix/repo/shells.nix +++ b/src/std/templates/rust/nix/repo/shells.nix @@ -22,8 +22,8 @@ deps = []; text = '' # ensure CARGO_HOME is populated - mkdir -p $PRJ_DATA_DIR/cargo - ln -snf -t $PRJ_DATA_DIR/cargo $(ls -d ${cell.rust.toolchain}/*) + mkdir -p "$PRJ_DATA_DIR/cargo" + ln -snf -t "$PRJ_DATA_DIR/cargo" $(ls -d ${cell.rust.toolchain}/*) ''; }; diff --git a/src/tests/flake.lock b/src/tests/flake.lock index c6dadbd0..bd7c6954 100644 --- a/src/tests/flake.lock +++ b/src/tests/flake.lock @@ -223,7 +223,10 @@ }, "haumea": { "inputs": { - "nixpkgs": "nixpkgs_2" + "nixpkgs": [ + "std", + "lib" + ] }, "locked": { "lastModified": 1685133229, @@ -419,21 +422,6 @@ "type": "github" } }, - "nixpkgs_2": { - "locked": { - "lastModified": 1681001314, - "narHash": "sha256-5sDnCLdrKZqxLPK4KA8+f4A3YKO/u6ElpMILvX0g72c=", - "owner": "nix-community", - "repo": "nixpkgs.lib", - "rev": "367c0e1086a4eb4502b24d872cea2c7acdd557f4", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "nixpkgs.lib", - "type": "github" - } - }, "nosys": { "locked": { "lastModified": 1668010795, @@ -546,12 +534,12 @@ }, "locked": { "lastModified": 0, - "narHash": "sha256-TVSN8JbeTuJxUEv6zzNHoSZ21/+HQ3uIRaRYtqcXqFs=", - "path": "/nix/store/i2xjj4w1rcyy5j59wgy18s1209gzsjvh-source", + "narHash": "sha256-XqH/66cLRYyiTlk2ob04WCeps5TFC0vyB4J+4foZBYw=", + "path": "/nix/store/056lk4aanlj3h831x4kj2hb1v9rgc98f-source", "type": "path" }, "original": { - "path": "/nix/store/i2xjj4w1rcyy5j59wgy18s1209gzsjvh-source", + "path": "/nix/store/056lk4aanlj3h831x4kj2hb1v9rgc98f-source", "type": "path" } }, @@ -613,8 +601,7 @@ "inputs": { "nixpkgs": [ "std", - "haumea", - "nixpkgs" + "lib" ] }, "locked": {