Compare commits

..

3 commits

3 changed files with 50 additions and 19 deletions

View file

@ -1,7 +1,7 @@
{ {
description = "Declaratively update your data."; description = "Declaratively update your data.";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
outputs = { nixpkgs, ... }: let outputs = { self, nixpkgs, ... }: let
system = "x86_64-linux"; system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
package = pkgs.stdenv.mkDerivation rec { package = pkgs.stdenv.mkDerivation rec {
@ -11,7 +11,10 @@
src = ./.; src = ./.;
deps = pkgs.callPackage ./build.zig.zon.nix {}; deps = pkgs.callPackage ./build.zig.zon.nix {};
nativeBuildInputs = [ pkgs.zig.hook pkgs.libgit2 pkgs.gpgme ]; 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; }; lib = builtins.import ./lib.nix { pkgs = pkgs; };
@ -20,13 +23,34 @@
options.programs.fooud.enable = lib.mkEnableOption ("fooud") options.programs.fooud.enable = lib.mkEnableOption ("fooud")
// { default = true; }; // { default = true; };
config = lib.mkIf config.programs.fooud.enable { 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; default = fooud;
}; };
# just x86 for now
packages.${system} = rec { default = package; fooud = default; }; 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
'';
}; };
} }

View file

@ -4,41 +4,48 @@ const std = @import("std");
const gpa = std.heap.page_allocator; const gpa = std.heap.page_allocator;
const NixStoreError = error{ /// Add a path to the store, this will copy the contents of path recursively
Failure, /// 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) NixStoreError![]const u8 { pub fn add(path: []const u8) error{Failure}![]const u8 {
const res = std.process.Child.run(.{ const res = std.process.Child.run(.{
.allocator = gpa, .allocator = gpa,
.argv = &[_][]const u8{ "nix", "store", "add", path }, .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 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(.{ _ = std.process.Child.run(.{
.allocator = gpa, .allocator = gpa,
.argv = &[_][]const u8{ "nix-store", "--realize", store_path }, .argv = &[_][]const u8{ "nix-store", "--realize", store_path },
}) catch return NixStoreError.Failure; }) catch return error.Failure;
return; 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(.{ _ = std.process.Child.run(.{
.allocator = gpa, .allocator = gpa,
.argv = &[_][]const u8{ "nix-store", "--add-root", root_path, "--indirect", store_path }, .argv = &[_][]const u8{ "nix-store", "--add-root", root_path, "--indirect", store_path },
}) catch return NixStoreError.Failure; }) catch return error.Failure;
return; 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(.{ _ = std.process.Child.run(.{
.allocator = gpa, .allocator = gpa,
.argv = &[_][]const u8{ "nix", "store", "delete", store_path }, .argv = &[_][]const u8{ "nix", "store", "delete", store_path },
}) catch { }) catch {
return NixStoreError.Failure; return error.Failure;
}; };
return; return;
} }

View file

@ -102,7 +102,7 @@ pub fn main() !void {
// delete the old nix store path // delete the old nix store path
if (dest_old_store_path) |path| { if (dest_old_store_path) |path| {
std.log.info("deleting old store path: {s}", .{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);
} }
} }