Skip to content

Commit

Permalink
Merge pull request #135 from divnix/auto-srcs
Browse files Browse the repository at this point in the history
pkgs: automatic source management
  • Loading branch information
nrdxp authored Feb 26, 2021
2 parents 314b18e + 088b51a commit afedb53
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 23 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
# Introduction
DevOS grants a simple way to use, deploy and manage [NixOS][nixos] systems for
personal and productive use. It does this by providing a convenient repository
structure; integrating several popular projects like
[home-manager][home-manager], and [devshell][devshell].
structure, integrating several popular projects like
[home-manager][home-manager], and [devshell][devshell], and offering useful
conveniences like
[automatic source updates](./pkgs#automatic-source-updates).

Skip the indeterminate nature of other systems, _and_ the perceived difficulty
of Nix. It's easier than you think!
Expand Down
10 changes: 10 additions & 0 deletions doc/flk/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ The `update` subcommand is a simple alias for:
nix flake update --recreate-lock-file --commit-lock-file
```
As it sounds, this will update your lock file, and commit it.

## Updating Package Sources
If you pass an input name then it will only update that input.

For example, you can update any
[package sources](../../pkgs#automatic-source-updates) you may have declared
in _pkgs/flake.nix_:
```sh
flk update srcs
```
23 changes: 18 additions & 5 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
deploy.inputs.flake-compat.follows = "flake-compat";
naersk.url = "github:nmattia/naersk";
naersk.inputs.nixpkgs.follows = "override";
flake-compat.url = "github:edolstra/flake-compat";
flake-compat.url = "github:BBBSnowball/flake-compat/pr-1";
flake-compat.flake = false;
srcs.url = "path:./pkgs";
};

outputs =
Expand Down
5 changes: 4 additions & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let
pathExists filter;

inherit (nixos.lib) fold filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix
recursiveUpdate genAttrs nixosSystem mkForce optionalAttrs;
recursiveUpdate genAttrs nixosSystem mkForce substring optionalAttrs;

# mapFilterAttrs ::
# (name -> value -> bool )
Expand Down Expand Up @@ -93,6 +93,8 @@ in

overlays = pathsToImportedAttrs overlayPaths;

mkVersion = src: "${substring 0 8 src.lastModifiedDate}_${src.shortRev}";

genPkgs = { self }:
let inherit (self) inputs;
in
Expand All @@ -107,6 +109,7 @@ in
(overridesOverlay overridePkgs)
self.overlay
(final: prev: {
srcs = self.inputs.srcs.inputs;
lib = (prev.lib or { }) // {
inherit (nixos.lib) nixosSystem;
flk = self.lib;
Expand Down
32 changes: 23 additions & 9 deletions pkgs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@ the supported systems listed in the package's `meta.platforms` attribute.
And, as usual, every package in the overlay is also available to any NixOS
[host](../hosts).

## Automatic Source Updates
There is the added, but optional, convenience of declaring your sources in
_pkgs/flake.nix_ as an input. This allows updates to be managed automatically
by simply [updating](../doc/flk/update.md#updating-package-sources) the lock
file. No more manually entering sha256 hashes!


## Example
pkgs/development/libraries/libinih/default.nix:
```nix
{ stdenv, meson, ninja, fetchFromGitHub, ... }:
let version = "r50";
{ stdenv, meson, ninja, lib, srcs, ... }:
let version = "r53";
in
stdenv.mkDerivation {
pname = "libinih";
inherit version;
src = fetchFromGitHub {
owner = "benhoyt";
repo = "inih";
rev = "${version}";
hash = "sha256-GF+TVEysaXJxSBBjMsTr2IQvRKlzdEu3rlPQ88PE3nI=";
};
src = srcs.libinih;
buildInputs = [ meson ninja ];
Expand All @@ -38,7 +40,7 @@ stdenv.mkDerivation {
-Ddistro_install=true
'';
meta = with stdenv.lib; {
meta = with lib; {
description = "Simple .INI file parser in C";
homepage = "https://github.com/benhoyt/inih";
maintainers = [ maintainers.divnix ];
Expand All @@ -56,4 +58,16 @@ final: prev: {
}
```

pkgs/flake.nix:
```nix
{
description = "Package sources";
inputs = {
libinih.url = "github:benhoyt/inih/r53";
libinih.flake = false;
};
}
```

[pkgs]: https://github.com/NixOS/nixpkgs/tree/master/pkgs
7 changes: 7 additions & 0 deletions pkgs/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
description = "Package sources";

inputs = { };

outputs = { ... }: { };
}
14 changes: 9 additions & 5 deletions shell/flk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ usage () {

printf " %-30s %s\n\n" \
"up" "Generate $DEVSHELL_ROOT/hosts/up-$HOSTNAME.nix" \
"update" "Update and commit the lock file" \
"get [core|community] DEST" "Copy the desired template to DEST" \
"update [INPUT]" "Update and commit the lock file" \
"get (core|community) [DEST]" "Copy the desired template to DEST" \
"iso HOST" "Generate an ISO image of HOST" \
"install HOST [ARGS]" "Shortcut for nixos-install" \
"home HOST USER [switch]" "Home-manager config of USER from HOST" \
"HOST [switch|boot|test]" "Shortcut for nixos-rebuild"
"HOST (switch|boot|test)" "Shortcut for nixos-rebuild"
}

case "$1" in
Expand All @@ -49,14 +49,18 @@ case "$1" in
;;

"update")
nix flake update --recreate-lock-file --commit-lock-file "$DEVSHELL_ROOT"
if [[ -n "$2" ]]; then
nix flake update --update-input "$2" --commit-lock-file "$DEVSHELL_ROOT"
else
nix flake update --recreate-lock-file --commit-lock-file "$DEVSHELL_ROOT"
fi
;;

"get")
if [[ "$2" == "core" || "$2" == "community" ]]; then
nix flake new -t "github:divnix/devos/$2" "${3:-flk}"
else
echo "flk get [core|community] {dest}"
echo "flk get (core|community) [DEST]"
exit 1
fi
;;
Expand Down

0 comments on commit afedb53

Please sign in to comment.