Skip to content

Commit ec013e2

Browse files
committed
Offline operation fixes, added integration test
1 parent 62f54c5 commit ec013e2

9 files changed

Lines changed: 48 additions & 13 deletions

File tree

default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{ lib, python3Packages, fetchPypi, nix-index, nix, hatch, amber-lang
2-
, ... }:
2+
, callPackage, ... }:
33

44
let
55
nixie_ver = "2026.03-a1";

flake.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
libfakedir = fakedir.packages.${system}.fakedir;
3636
} else {});
3737

38+
checks = {
39+
rootless = pkgs.callPackage ./tests/rootless.nix { inherit (self.packages.${system}) nixie sources static-bins; };
40+
};
41+
3842
devShells = {
3943
default = pkgs.mkShell {
4044
# These dependencies aren't involved in the build process, but are

nixie/cli/commands/init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _cmd(console: Console, nocommand=False, **args):
2727
Path('.').rglob('*.nix').send(None)
2828
outn = './nix-shell'
2929
skipgen = True
30-
except StopIteration:
30+
except:
3131
skipgen = False
3232
outn = './nix'
3333
else:

nixie/cli/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ def get_appcache():
3636
cach.mkdir(exist_ok=True, parents=True)
3737
return cach
3838

39-
def mktmp() -> str:
39+
def mktmp() -> Path:
4040
'''Create a temporary work directory and hook its deletion at exit.
4141
'''
4242
tdir = tempfile.mkdtemp(prefix='nixie-')
4343
cleanup = lambda: shutil.rmtree(tdir)
4444
atexit.register(cleanup)
45-
return tdir
45+
return Path(tdir)
4646

4747
def pick(prompt: str, opts, open_ended = False, **ws):
4848
'''Pick from a selection of items, displaying a leading prompt.

nixie/cli/fetchers.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def eval_latest_sources(args: dict, st = None):
3939
except RuntimeError as e:
4040
srcs_eval = _rsrc_fallback('srcs', e)
4141
else:
42-
srcs_eval = args['sources_derivation']
42+
srcs_eval = nix.hashify(args['sources_derivation'])
4343
if args['binaries_derivation'] is None:
4444
try:
4545
bins_eval = nix.flake_eval(nix.EXPR_NIXIE_BINARIES)
@@ -48,17 +48,20 @@ def eval_latest_sources(args: dict, st = None):
4848
except RuntimeError as e:
4949
bins_eval = _rsrc_fallback('bins', e)
5050
else:
51-
bins_eval = args['binaries_derivation']
51+
bins_eval = nix.hashify(args['binaries_derivation'])
5252
debug(f"Sources derivation: {srcs_eval}")
5353
debug(f"Binaries derivation: {bins_eval}")
5454
return srcs_eval, bins_eval
5555

5656
def _tmplink(tdir: Path, drv: str):
5757
locdrv = list(Path('/nix/store/').glob(f'{drv}*'))
58+
target = tdir.joinpath(drv)
5859
if len(locdrv) == 0:
5960
error('Derivation could not be found locally. Check your Internet connection and supplied derivation hash then try again.')
6061
else:
61-
tdir.joinpath('{drv}').symlink_to(locdrv[0])
62+
target.rmdir() # fetchCachix may have left an empty dir
63+
target.symlink_to(locdrv[0])
64+
debug(f"Created symlink: {drv} -> {locdrv[0]}")
6265

6366
def prefetch_resources(tdir: Path,
6467
feats: script.NixieFeatures,

nixie/output/tarball.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ def writeInto(self, dest: BytesIO, tmpdir: Path = None):
9191
for name, tgt in self.features.pinned_channels.items():
9292
self._push_channel(m, name, tgt)
9393
if self.features.include_sources:
94-
srcs = [ f for f in tmpdir.joinpath(nix.hashify(self.features.sources_drv)).iterdir()
94+
srcs = [ f for f in tmpdir.joinpath(nix.hashify(self.features.sources_drv)).resolve().iterdir()
9595
if f.name != 'filelist' ]
9696
for f in srcs:
9797
with tf.open(f, mode='r:*') as fm:
9898
self.transplant(m, fm, 'sources')
9999
if self.features.include_bins:
100-
bins = [ f for f in tmpdir.joinpath(nix.hashify(self.features.bins_drv)).iterdir()
100+
bins = [ f for f in tmpdir.joinpath(nix.hashify(self.features.bins_drv)).resolve().iterdir()
101101
if f.name != 'filelist' ]
102102
for f in bins:
103103
m.add(f, path.basename(f))

src/common.ab

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,11 @@ pub fun untar(member: Text, dump: Bool = false): Text?
120120
}
121121

122122
trust $rm {archive}$
123-
124-
return tar_out
123+
if dump {
124+
return tar_out
125+
} else {
126+
return member
127+
}
125128
}
126129

127130
/// Checks that a list of commands are available at runtime.

src/platform.ab

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,19 @@ pub fun get_nix_root(): Text
5858
}
5959

6060
/// Return the path to the user's cache directory on the current system.
61+
///
62+
/// Will create the directory in the rare case where it does not exist.
6163
pub fun get_cache_root(): Text
6264
{
6365
let userhome = trust env_var_get("HOME")
6466
let osname = get_osname()
67+
let result = ""
6568
if {
66-
osname == "Darwin": return "{userhome}/Library/Caches"
67-
else: return "{userhome}/.cache"
69+
osname == "Darwin": result = "{userhome}/Library/Caches"
70+
else: result = "{userhome}/.cache"
6871
}
72+
trust $mkdir -p {result}$
73+
return result
6974
}
7075

7176
/// Return the path to the root of the Git repository the script is located in.

tests/rootless.nix

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{ pkgs, nixie, sources, static-bins }:
2+
pkgs.testers.nixosTest {
3+
name = "nixie-runs-rootless";
4+
nodes = {
5+
machine = {
6+
environment.systemPackages = with pkgs; [
7+
nixie
8+
git
9+
];
10+
};
11+
};
12+
13+
testScript = ''
14+
start_all()
15+
16+
machine.succeed("git init")
17+
machine.succeed("nixie init --sources-derivation ${sources} --binaries-derivation ${static-bins} --with-binaries")
18+
machine.succeed("./nix --nixie-ignore-system --version")
19+
'';
20+
}

0 commit comments

Comments
 (0)