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 + ''; }; } diff --git a/src/NixStore.zig b/src/NixStore.zig index fbbaed4..0fd66b9 100644 --- a/src/NixStore.zig +++ b/src/NixStore.zig @@ -4,41 +4,48 @@ const std = @import("std"); const gpa = std.heap.page_allocator; -const NixStoreError = error{ - Failure, -}; - -pub fn add(path: []const u8) NixStoreError![]const u8 { +/// 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, .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 { +/// 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, .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 { +/// 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, .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 { +/// Delete a path from the store. +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); } }