Compare commits
No commits in common. "59cd849928e783848a4c9e0c0c04fa80eabe287d" and "27ace6292577b17ed35b03c39707137bdd3257ac" have entirely different histories.
59cd849928
...
27ace62925
3 changed files with 19 additions and 50 deletions
36
flake.nix
36
flake.nix
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
description = "Declaratively update your data.";
|
||||
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
outputs = { self, nixpkgs, ... }: let
|
||||
outputs = { nixpkgs, ... }: let
|
||||
system = "x86_64-linux";
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
package = pkgs.stdenv.mkDerivation rec {
|
||||
|
|
@ -11,46 +11,22 @@
|
|||
src = ./.;
|
||||
deps = pkgs.callPackage ./build.zig.zon.nix {};
|
||||
nativeBuildInputs = [ pkgs.zig.hook pkgs.libgit2 pkgs.gpgme ];
|
||||
zigBuildFlags = [
|
||||
"--system" "${deps}"
|
||||
"-Doptimize=Debug"
|
||||
];
|
||||
zigBuildFlags = [ "--system" "${deps}" ];
|
||||
};
|
||||
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
|
||||
pkgs.nix
|
||||
package
|
||||
];
|
||||
environment.systemPackages = [ pkgs.libgit2 pkgs.gpgme 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
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,48 +4,41 @@ 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 NixStoreError = error{
|
||||
Failure,
|
||||
};
|
||||
|
||||
pub fn add(path: []const u8) NixStoreError![]const u8 {
|
||||
const res = std.process.Child.run(.{
|
||||
.allocator = gpa,
|
||||
.argv = &[_][]const u8{ "nix", "store", "add", path },
|
||||
}) catch return error.Failure;
|
||||
}) catch return NixStoreError.Failure;
|
||||
|
||||
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 {
|
||||
pub fn realize(store_path: []const u8) NixStoreError!void {
|
||||
_ = std.process.Child.run(.{
|
||||
.allocator = gpa,
|
||||
.argv = &[_][]const u8{ "nix-store", "--realize", store_path },
|
||||
}) catch return error.Failure;
|
||||
}) catch return NixStoreError.Failure;
|
||||
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 {
|
||||
pub fn root(store_path: []const u8, root_path: []const u8) NixStoreError!void {
|
||||
_ = std.process.Child.run(.{
|
||||
.allocator = gpa,
|
||||
.argv = &[_][]const u8{ "nix-store", "--add-root", root_path, "--indirect", store_path },
|
||||
}) catch return error.Failure;
|
||||
}) catch return NixStoreError.Failure;
|
||||
return;
|
||||
}
|
||||
|
||||
/// Delete a path from the store.
|
||||
pub fn delete(store_path: []const u8) error{Failure}!void {
|
||||
pub fn delete(store_path: []const u8) NixStoreError!void {
|
||||
_ = std.process.Child.run(.{
|
||||
.allocator = gpa,
|
||||
.argv = &[_][]const u8{ "nix", "store", "delete", store_path },
|
||||
}) catch {
|
||||
return error.Failure;
|
||||
return NixStoreError.Failure;
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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});
|
||||
try NixStore.delete(path);
|
||||
NixStore.delete(path) catch |err| if (err == error.Failure) return err;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue