viperML / nh

Yet another nix cli helper
European Union Public License 1.2
845 stars 33 forks source link

Period in username not "escaped" #135

Closed horriblename closed 1 month ago

horriblename commented 1 month ago

on my work laptop my username is "firstname.lastname" and running nh home switch . gives this error:

'...' does not provide attribute 'packages.x86_64-darwin.homeConfigurations.firstname.lastname.config.home.activationPackage', 'legacyPackages.x86_64-darwin.homeConfigurations.firstname.lastname.config.home.activationPackage' or 'homeConfigurations.firstname.lastname.config.home.activationPackage'

-c firstname.lastname doesn't help either

viperML commented 1 month ago

Could paste the output with --verbose?

horriblename commented 1 month ago
TRACE nh::logging:86: Logging OK
DEBUG nh:21: args=NHParser { verbose: true, command: Home(HomeArgs { subcommand: Switch(HomeRebuildArgs { common: CommonRebuildArgs { dry: false, ask: false, flakeref: FlakeRef("."), update: false, no_nom: false, diff_provider: "nvd diff" }, configuration: None, extra_args: [], backup_extension: None }) }) }
DEBUG nh::home:40: out_dir: TempDir { path: "/tmp/nh-home-c8DPMs" }
DEBUG nh::home:41: out_link "/tmp/nh-home-c8DPMs/result"
DEBUG configuration_exists: nh::commands:79: cmd=Exec { nix eval '.#homeConfigurations' --apply ' x: x ? "firstname.lastname@C02D60Q6MD6V" ' } flakeref=FlakeRef(".") configuration="firstname.lastname@C02D60Q6MD6V"
warning: Git tree '/Users/firstname.lastname/privrepo/dots.nix' is dirty
DEBUG configuration_exists: nh::home:192: result="false\n" flakeref=FlakeRef(".") configuration="firstname.lastname@C02D60Q6MD6V"
DEBUG configuration_exists: nh::home:181: return=false flakeref=FlakeRef(".") configuration="firstname.lastname@C02D60Q6MD6V"
DEBUG configuration_exists: nh::commands:79: cmd=Exec { nix eval '.#homeConfigurations' --apply ' x: x ? "firstname.lastname" ' } flakeref=FlakeRef(".") configuration="firstname.lastname"
warning: Git tree '/Users/firstname.lastname/privrepo/dots.nix' is dirty
DEBUG configuration_exists: nh::home:192: result="true\n" flakeref=FlakeRef(".") configuration="firstname.lastname"
DEBUG configuration_exists: nh::home:181: return=true flakeref=FlakeRef(".") configuration="firstname.lastname"
DEBUG nh::home:56: hm_config_name: firstname.lastname
> Building home configuration
DEBUG nh::commands:136: cmd=Pipeline { nix build '.#homeConfigurations.firstname.lastname.config.home.activationPackage' --log-format internal-json --verbose --out-link /tmp/nh-home-c8DPMs/result | nom --json }
warning: Git tree '/Users/firstname.lastname/privrepo/dots.nix' is dirty
error: flake 'git+file:///Users/firstname.lastname/privrepo/dots.nix' does not provide attribute 'packages.x86_64-darwin.homeConfigurations.firstname.lastname.config.home.activationPackage', 'legacyPackages.x86_64-darwin.homeConfigurations.firstname.lastname.config.home.activationPackage' or 'homeConfigurations.firstname.lastname.config.home.activationPackage'
┏━ 1 Errors:
┃ error: flake 'git+file:///Users/firstname.lastname/privrepo/dots.nix' does not provide attribute 'packages.x86_64-darwin.homeConfigurations.firstname.lastname.config.home.activationPackage', 'legacyPackages.x86_64-darwin.homeConfigurations.firstname.lastname.config.home.activationPackage' or 'homeConfigurations.firstname.lastname.config.home.activationPackage'
┣━━━
┗━ ∑ ⚠ Exited with 1 errors reported by nix at 17:53:42 after 0s
Error:
   0: Command exited with status Exited(1)

Location:
   src/commands.rs:151

for reference, home-manager switch --flake firstname.lastname worked fine

viperML commented 1 month ago

it seems we need to handle the dot to pass it properly to nix build

ToyVo commented 1 month ago

This line https://github.com/viperML/nh/blob/master/src/home.rs#L59

            "{}#homeConfigurations.{}.config.home.activationPackage",

should be changed to

            "{}#homeConfigurations.\"{}\".config.home.activationPackage",

that won't effect anyone who doesn't have a .

ToyVo commented 1 month ago

This line is for nixos, could be useful there too, it doesn't harm. https://github.com/viperML/nh/blob/master/src/nixos.rs#L46

viperML commented 1 month ago

I'm curious about how @horriblename deals with this on a daily basis, as apparently shells like bash and fish interpret the quotes.

Dumping the received argv[1] shows the following:

$ gcc -Wall ./main.c -o main

$ ./main .#foo."a.b".baz
|.|#|f|o|o|.|a|.|b|.|b|a|z

$ ./main .#foo.\"a.b\".baz
|.|#|f|o|o|.|"|a|.|b|"|.|b|a|z

HM adds the escaped quotes here: https://github.com/nix-community/home-manager/blob/afd2021bedff2de92dfce0e257a3d03ae65c603d/home-manager/home-manager#L213

horriblename commented 1 month ago

I don't recall ever needing to type literal " in the shell luckily :grinning: but \" is probably what I'd do as well