From 8cf602987251138602e77d728323ea3eb4e167e0 Mon Sep 17 00:00:00 2001 From: Squibid Date: Sat, 6 Dec 2025 03:53:03 -0500 Subject: [PATCH 1/3] refine my errors --- src/NixStore.zig | 20 ++++++++------------ src/main.zig | 2 +- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/NixStore.zig b/src/NixStore.zig index fbbaed4..ae71e1e 100644 --- a/src/NixStore.zig +++ b/src/NixStore.zig @@ -4,41 +4,37 @@ const std = @import("std"); const gpa = std.heap.page_allocator; -const NixStoreError = error{ - Failure, -}; - -pub fn add(path: []const u8) NixStoreError![]const u8 { +pub fn add(path: []const u8) error{Failure}![]const u8 { const res = std.process.Child.run(.{ .allocator = gpa, .argv = &[_][]const u8{ "nix", "store", "add", path }, - }) catch return NixStoreError.Failure; + }) catch return error.Failure; return res.stdout[0 .. res.stdout.len - 1]; // to chop off the \n } -pub fn realize(store_path: []const u8) NixStoreError!void { +pub fn realize(store_path: []const u8) error{Failure}!void { _ = std.process.Child.run(.{ .allocator = gpa, .argv = &[_][]const u8{ "nix-store", "--realize", store_path }, - }) catch return NixStoreError.Failure; + }) catch return error.Failure; return; } -pub fn root(store_path: []const u8, root_path: []const u8) NixStoreError!void { +pub fn root(store_path: []const u8, root_path: []const u8) error{Failure}!void { _ = std.process.Child.run(.{ .allocator = gpa, .argv = &[_][]const u8{ "nix-store", "--add-root", root_path, "--indirect", store_path }, - }) catch return NixStoreError.Failure; + }) catch return error.Failure; return; } -pub fn delete(store_path: []const u8) NixStoreError!void { +pub fn delete(store_path: []const u8) error{Failure}!void { _ = std.process.Child.run(.{ .allocator = gpa, .argv = &[_][]const u8{ "nix", "store", "delete", store_path }, }) catch { - return NixStoreError.Failure; + return error.Failure; }; return; } diff --git a/src/main.zig b/src/main.zig index 55423a5..aacd242 100644 --- a/src/main.zig +++ b/src/main.zig @@ -102,7 +102,7 @@ pub fn main() !void { // delete the old nix store path if (dest_old_store_path) |path| { std.log.info("deleting old store path: {s}", .{path}); - NixStore.delete(path) catch |err| if (err == error.Failure) return err; + try NixStore.delete(path); } } From 0ec816397d2a91be41facd9905d3fbf31f3ea13c Mon Sep 17 00:00:00 2001 From: Squibid Date: Sat, 6 Dec 2025 14:53:00 -0500 Subject: [PATCH 2/3] add some docs to the nix store which may help someone with the same problems --- src/NixStore.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/NixStore.zig b/src/NixStore.zig index ae71e1e..0fd66b9 100644 --- a/src/NixStore.zig +++ b/src/NixStore.zig @@ -4,6 +4,10 @@ const std = @import("std"); const gpa = std.heap.page_allocator; +/// Add a path to the store, this will copy the contents of path recursively +/// into the store and return a (hopefully) valid store path. To try and keep +/// this store path valid you should follow this with a call to realize() and +/// then root the store path. pub fn add(path: []const u8) error{Failure}![]const u8 { const res = std.process.Child.run(.{ .allocator = gpa, @@ -13,6 +17,9 @@ pub fn add(path: []const u8) error{Failure}![]const u8 { return res.stdout[0 .. res.stdout.len - 1]; // to chop off the \n } +/// This tries to tell the store that a store_path should stick around a while +/// longer, there's a chance that it doesn't listen and removes that store_path +/// but in my testing it seemed to stick around. pub fn realize(store_path: []const u8) error{Failure}!void { _ = std.process.Child.run(.{ .allocator = gpa, @@ -21,6 +28,9 @@ pub fn realize(store_path: []const u8) error{Failure}!void { return; } +/// This tells the nix store to not gc our new store_path because it has a +/// dependency at root_path and that only if root_path doesn't exist anymore +/// it can delete store_path. pub fn root(store_path: []const u8, root_path: []const u8) error{Failure}!void { _ = std.process.Child.run(.{ .allocator = gpa, @@ -29,6 +39,7 @@ pub fn root(store_path: []const u8, root_path: []const u8) error{Failure}!void { return; } +/// Delete a path from the store. pub fn delete(store_path: []const u8) error{Failure}!void { _ = std.process.Child.run(.{ .allocator = gpa, From 59cd849928e783848a4c9e0c0c04fa80eabe287d Mon Sep 17 00:00:00 2001 From: Squibid Date: Sat, 6 Dec 2025 14:55:12 -0500 Subject: [PATCH 3/3] update the flake --- flake.nix | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index e3a05f8..e14cf17 100644 --- a/flake.nix +++ b/flake.nix @@ -1,7 +1,7 @@ { description = "Declaratively update your data."; inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - outputs = { nixpkgs, ... }: let + outputs = { self, nixpkgs, ... }: let system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; package = pkgs.stdenv.mkDerivation rec { @@ -11,22 +11,46 @@ src = ./.; deps = pkgs.callPackage ./build.zig.zon.nix {}; nativeBuildInputs = [ pkgs.zig.hook pkgs.libgit2 pkgs.gpgme ]; - zigBuildFlags = [ "--system" "${deps}" ]; + zigBuildFlags = [ + "--system" "${deps}" + "-Doptimize=Debug" + ]; }; - in { + in { lib = builtins.import ./lib.nix { pkgs = pkgs; }; nixosModules = rec { fooud = { pkgs, lib, config, inputs, ... }: { options.programs.fooud.enable = lib.mkEnableOption ("fooud") // { default = true; }; config = lib.mkIf config.programs.fooud.enable { - environment.systemPackages = [ pkgs.libgit2 pkgs.gpgme package ]; + environment.systemPackages = [ + pkgs.libgit2 + pkgs.gpgme + pkgs.nix + package + ]; }; }; default = fooud; }; - - # just x86 for now packages.${system} = rec { default = package; fooud = default; }; + + checks.${system}.build = let + package = self.packages.${system}.default; + in pkgs.runCommand "fooud-build" { buildInputs = [ + pkgs.git + pkgs.nix + ]; } '' + mkdir repo + git -C repo init > /dev/null 2>&1 + echo "hi" > repo/README.md + git -C repo config user.email "you@example.com" > /dev/null 2>&1 + git -C repo config user.name "Your Name" > /dev/null 2>&1 + git -C repo add . > /dev/null 2>&1 + git -C repo commit -m "initial commit" > /dev/null 2>&1 + + # this check won't succeed until I find a way to run a chroot store + ${package}/bin/fooud --git repo --dest test + ''; }; }